I just started to learn C++ and have some problem when I read a hole line from a textfile. I would be grateful if anyone can tell me what is wrong with my code.
I'm using Borland Developer Studio 2006.
//------------------------------------------------------------------------------
// getFile
//------------------------------------------------------------------------------
// Read from a textfile
// Input: nameList[] (string) , FILENAME (string)
// output: countName (int)
//------------------------------------------------------------------------------
int getFile(vector<string> &nameList,const string FILENAME)
{
int countName = 0;
fstream nameFile;
nameFile.open(FILENAME.c_str(), ios::in);
//Read line by line from file to nameList until EndOfFile
while (getline(nameFile,nameList[countName]))
{
countName++;
}
nameFile.close();
return countName;
}