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