我正在尝试从文本文件中读取并对输入进行标记化。在我意识到我忘记关闭我的 ifstream 之前,我一直遇到段错误。我添加了关闭调用,现在它无限循环。我现在只是想学习如何使用 strtok,这就是代码看起来并不完整的原因。
void loadInstructions(char* fileName)
{
ifstream input;
input.open(fileName);
while(!input.eof());
{
string line;
getline (input,line);
char * lineChar = &line[0];
//instruction cmd; //This will be used later to store instructions from the parse
char * token;
token = strtok (lineChar," ");
// just trying to get the line number for now
int lineNumber = atoi(token);
cout << lineNumber << "\n";
}
input.close();
}
输入文件:(一行)
5 +8 0 0 25
最佳答案
这 while(input.good());
可能不是您想要的...
关于c++ - 为什么这个IO操作会无限循环呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5175831/