3
我想从UNIX上的二进制文件读取。该文件存在并且包含多个数据信息。阅读中的fstream unix问题
的代码看起来是这样的:
fstrean fstrHandler;
string strFileName;
char Buf[30000];
fstrHandler.open(strFileName.c_str(), ios::in | ios::binary);
fstrHandler.seekp(0, std::ios_base::beg);
std::cout<< "Posi before read= "<< fstrHandler.tellg()<<endl; //*** Show after running 0
fstrHandler.read (Buf, 400);
std::cout<< "Posi after read= "<< fstrHandler.tellg()<<endl; //*** Show after running 0
std::cout<< " gcount()= "<< fstrHandler.gcount()<< << endl; //*** Show after running 0
if (fstrHandler.eof()) {
fstrHandler.clear();
}
读我得到的文件中的位置仍然是零零后,但该文件不为空。
s/fstrean/fstream /。除此之外,你应该检查'fstream :: open`是否成功,例如:`assert(fstrHandler.good())`。 – jweyrich 2011-02-02 12:57:19
我没有添加它,但它存在 – 2011-02-02 13:13:44