I need to read in a string and then an integer until the user indicates end of input (ctrl-d in linux). Again, I am stuck. Currently I have a while loop:
while (getline(cin, line))
However, that gives an entire line and then I cannot seem to separate the string from the integer. Suggestions would be most appreciated! 🙂
If the string and the integer is separated by whitespace;
Do this:
You can choose your own delimiter, by writing a manipulator yourself.
Another approach would be to do it your way, and put the input line into a stringstream and extract the string and numbers from it. That approach seems roundabout to me as you get strings from a stream only to put it into another stream.