Usually I write a control loop as follows:
Loop that enters writes ints into vector nVec until “done” is entered.
while (cin >> sString){
if (sString="done")
{
break;
}
nVec.push_back(sString);
}
this works fine, but how would I go about doing this if I wanted the loop to end once the user entered nothing (just pressed enter)?
You can’t “not enter anything” into your token-wise extraction. The only way for your loop to stop is for the user to send end-of-file (Ctrl-D on Linux). I would personally say that this is the correct behaviour, but if you want to end on empty input, you need to read lines:
This way, you tokenize each line into possibly multiple books. If you just want one book per line, rip out the inner loop and just say
std::istringstream(line) >> book;.