我知道这已被问及前几次,我读了与它有关的线程,但那里的解决方案没有为我工作。倒带ifSteam在C++
ifstream myFile;
myFile.open("largefile.txt");
if (myFile.is_open())
{
while (!myFile.eof()) //step through each line until end of file
{
myFile>> str;
if(str.size() < 5){
amount++;
}
}
}
myFile.seekg(0, ios::beg);
if (myFile.is_open())
{
for(int i=0; i != random_integer; i++) //step through each line until random line reached
{
myFile>> str;
if(i == random_integer-1){
cout << "\n";
cout << str;
cout << "\n";
cout << str.size();
}
}
}
myFile.close();
我读过在while语句中使用EOF是一个坏主意,最新的选择是什么?而且我怎么才能倒回第二个循环,因为seekg没有工作,我不想关闭文件并再次打开,并且文件大到可以真正读入数组?我敢肯定,这是一个简单的解决方案,我只是对C++很陌生。
如果蒸了,那么可能有些火了。 – Benoit 2012-03-05 15:37:18