【发布时间】:2013-03-21 04:16:36
【问题描述】:
当我在 myFile 中到达 EOF 时,Seekg 似乎不起作用。
ifstream myFile("/path/file");
for(int i; i < 10; i++){
myFile.seekg(0);//reset position in myFile
while(getline(myFile, line)){
doSomething
}
}
所以,现在我每个循环都打开输入流:
for(int i; i < 10; i++){
ifstream myFile("/path/file");//reset position in myFile
while(getline(myFile, line)){
doSomething
}
}
但我宁愿寻求位置 0。我怎样才能做到这一点?
【问题讨论】:
-
seekg() function fails 的可能重复项
标签: c++ ifstream getline seekg