问题描述
|
我想逐行读取文件,这是代码:
map<int,string>WordList ; //int is the key,string the returnad value
int GetWordList(char* file)
{
WordList.clear();
char getch;
int wordindex=-1;
string tempstring=\"\";
ifstream myFile(file);
while (!myFile.eof())
{
myFile.get(getch);
if (getch==\'\\r\') continue; // skipping \'\\r\' characters
if (getch == \'\\n\' || myFile.eof() )
{
WordList[++wordindex]=tempstring;
tempstring=\"\";
}else tempstring+=getch;
}
return wordindex; //returns the maximum index
}
我打电话了
int totalStudents = GetWordList(\"C:\\Students.txt\");
该文件中有三行内容,
但是当我运行程序时,它不会从while循环中退出,而且WordList始终为0,
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)