Search code examples
c++ifstream

Function reading file


It supposed to read from a file and store in my class variable. But function ain't reading. Where is problem here ?

void GetGameInfo (const string fv, GetInfo G[], int & questionN)
{
    string gameSection, gameDificulty;
    int gameNumber;
    ifstream fd(fv);
    while(fd != 0)
    {
        fd >> gameSection >> gameDificulty >> gameNumber;
        G[questionN].takeGame( gameSection, gameDificulty, gameNumber);
        fd.ignore(100, '\n');
        questionN++;
    }
}

Solution

  • You should be reading like following

    while ( fd >> gameSection >> gameDificulty >> gameNumber )
    {
       //...
    
    }