-
cin input error
Hi, I am currently working on a console app and I have run into one error that throws off the feel of my program. My program is kind of like the skeleton for a miniature compiler with the feel of python. The problem I am having is in generataing the next line. If the user entered the code for that line, and then pressed enter to terminate the line, everything works fine. The problem is when they don't enter any values and press enter, the program keeps waiting until a value is entered. Does anyone know how I can determine if a user pressed enter at all in a console app?? Thanks in advance.
-
-
cin.get()
?
i probably don't understand the question..
-
std::getline(stream, target, delimiter);
so basicly
std::getline(std::cin, var, '\n');
-
You are probably using cin >> to read in values. As has been recommended you should use getline to read in the line into a string.
The important next step is to then put that entire string into an istringstream. Then use that istringstream like you were using cin before.
With the istringstream if the user didn't input any value and you try to read from it, it will set a failbit because it will be empty. If you just used cin then it would wait until the user typed in non-whitespace like you are experiencing.