我知道這已被問及前幾次,我讀了與它有關的線程,但那裏的解決方案沒有爲我工作。倒帶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