read does not work with basic_ifstream< unsigned char >

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all,
while trying to avoid a cast when reading from a file to a buffrer,
I changed the type of the input file from ifstream to basic_ifstream< 
unsigned char >, and suddenly read() does not work anymore. 

Is this the expected behaviour? and if it is so, why?

This is a small test program that shows the problem:

#include <fstream>
#include <iostream>

using namespace std;

typedef char mytype;
//typedef unsigned char mytype;

int main(int argc, char **argv)
{
        basic_ifstream< mytype > in("testfile", ios::binary);

        mytype buf[100];
        in.read(buf, 100);
        cout << in.gcount() << " bytes read." << endl;

        in.close();
}

If mytype is char, the program prints "6" (the number of characters in 
testfile), if it is defined as unsigned char, it prints out 0.

Thanks for any clarification,
Luciano 

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux