目前我有一个从ifstream读取无符号字符的代码:
ifstream in;
unsigned char temp;
in.open ("RANDOMFILE", ios::in | ios::binary);
in.read (&temp, 1);
in.close ();
这是否正确?我还尝试将无符号字符写入ofstream:
ofstream out;
unsigned char temp;
out.open ("RANDOMFILE", ios::out | ios::binary);
out.write (&static_cast<char>(temp), 1);
out.close ();
但是我写代码时遇到了以下错误:
error C2102: '&' requires l-value
并且出现了读取错误:
error C2664: 'std::basic_istream<_Elem,_Traits>::read' : cannot convert parameter 1 from 'unsigned char *' to 'char *'
如果有人能告诉我代码哪里出了问题,或者如何从fstream中读写无符号字符,我将不胜感激。