I want to read file line to line , here is code :
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
}
I have called
int totalStudents = GetWordList("C:\Students.txt");
I have three line in that file , but when I run program , it will not exit from while loop and also WordList is always 0 ,