我测试下面的代码:关于在C++中ifstream的seekg()函数的问题?
int _tmain(int argc, _TCHAR* argv[])
{
int sum = 0;
int x;
ifstream inFile;
inFile.open("test.txt");
if (!inFile) {
cout << "Unable to open file";
exit(1); // terminate with error
}
while (inFile >> x) {
cout << x << endl;
}
cout << "-----------------------------" << endl;
// Reading from beggining file again
inFile.seekg(0, ios::beg);
while (inFile >> x) {
cout << x << endl;
}
inFile.close();
return 0;
}
在上面的代码,我想读文件,然后移动鼠标指针到文件的开头,然后再次读取。 我已经使用inFile.seekg(0, ios::beg);
回到文件的开头,但它不起作用? 任何人都可以帮助我吗? 谢谢
neg没有解释,奇怪的缩进,由于错误的注释语法,C风格的转换,什么是'reg_no',我可以继续编译。 – 2015-12-16 13:11:25