I'm having a bit of a problem with getline(). In line 66, the "cin" will not allow any spaces (ex: White Wolf), but when I change it to getline(), it works, however, it changes the program and ends up doing something I don't want it to. What can I do?
If I change line 66 to getline(), it doesn't let me enter a string for line 34 and simply displays the error message in line 36. the error message in line 36 is only suppose to execute when nothing is put into line 66, but it doesn't allow me to put anything into it in the first place.
Input taken with the >> operator stops at whitespace so if you want the "line" (all string info up to CR) you will need to use cin.getline() if the input goes into a cstring. You could also use std::getline() if you want to read from cin into a string. If you want to mix using getline() and the >> operator you need to know that there may be leftovers in the buffer that will trip you up. You can read up about it here: http://augustcouncil.com/~tgibson/tutorial/iotips.html
The operator >> skip all leading whitespace characters before extracting the desired value but does not discard the end of line character left in the buffer. On line 74, a double value is extracted and stored into price. The marker position in the input stream is left on '\n'.
getline() does not skip the leading whitespace characters and will extract any character until it finds a delimiter character which is, by default, the new line character '\n'.
Therefore, when statement 66 is executed, getline() read the input buffer and finds the new line character immediately. bidder1 ends up with an empty string.
Please note that getline(), after having extracted the desired characters, will discard the delimiter characters.
You can verify this by ignoring the first character left ('\n') in cin buffer after line 74: