Hey guys I've trouble understanding (inFile >> ch).get();. After I added this piece of code, it start working. I found the solution on the Internet but I really want to know what's happening right there.
User is supposed to enter a specific text file which contains some names and the amount of money they donated. Textfile is down below
So, is it a "new line" in the text document that's messing the whole thing up? And when I'm adding .get() it "takes care" of the "new line".
The issue with the new line is the use of the function getline(). By default, getline() extracts characters up until ( and including ) a newline character. Since the >> operator doesn't extract a trailing newline, a call to getline() after >> will create an empty string.
The preferred method is to use ignore() after using a >> operator:
1 2 3
cin >> x;
cin.ignore( 80, '\n' ); // ignore until 80 characters have been ignored, or a newline has been extracted