mardi 25 janvier 2022

Why does getline function discard the middle string?

I'm pretty new to C++ and StackOverflow. I'm trying to get only the marks from the string which is read from the file. Whenever I tried doing it, it outputs 50 and 75 only. Can someone explain to me why does it print only print these 2 lines only, please?

Expected output: 50,80,75

int main()
{
    string storeContents;
    string temp;
    string fileName("input.txt");
    ifstream inFile(fileName);

    while(!inFile.eof())
    {
        getline(inFile,storeContents);
        getline(inFile,storeContents, ' ');
        getline(inFile,storeContents, ' ');
        getline(inFile,storeContents, ' ');
        getline(inFile,storeContents, '\n');
        cout << storeContents << endl;
    }

    return 0;
}

Actual output: 50 75

File contents:

102234 962 4

Data_Structures ICT283 3 50

Security_Policy ICT380 1 80

Programming ICT159 4 75

Aucun commentaire:

Enregistrer un commentaire