【发布时间】:2011-06-02 06:58:43
【问题描述】:
我的 C++ 程序编译并运行,直到我从 main() 调用此函数:
int uword(){fstream infile("numbers.txt");
fstream exfile("wordlist.txt");
string numb[numoflines];
string lines[numoflines];
number = 1;
line = 1;
for(int i=0;i<numofline;++i)
{
getline (infile,number);
numb[i] = number; //I think this is causing the problem
getline (exfile,line);
lines[i] = line; //This too
}
infile.close();
exfile.close();
string yourword;
这里的某些东西导致它崩溃,在调试中它弹出“程序中引发访问冲突(分段错误)”。
编辑:我的错误是在 for 循环中使用 !infile.eof。
【问题讨论】:
-
您的输入循环不正确。 GMan 很好地解释了如何正确处理an answer to one of the C++ FAQ questions 中的输入。
-
将 !infile.eof() 更改为 i
-
你的意思是 i
-
是的,这就是我的意思,当我在我的代码中更改它时,它现在可以工作了。 :)