Luciano Montanaro
2006-10-06 10:20:11 UTC
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
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