naraku-
Using cin >> action could be a problem, as it is delimited by white space so the string "this is a string" passed to cin will set action to just "this". If you use getline(cin, action); you will get the entire string. I dont know if this is the cause of your issue but its worth a look. |
The program is designed to operate using single word commands for precisely this reason. I realize that if this type of statement was used immediately prior to this point in the code,( say something like
cin >> action0;
) and the user input multiple words separated by whitespaces, ("this is a string") this
cin >> action;
segment would then take in the word "is" as its argument.
However, if this was the case, the program would generate my error message "Invalid input, please re-enter command". Then it would repeat the loop, and take in "a", generate an error, repeat, take in "string", generate an error, and then when it repeated it would await user input.
This is what i was saying to Cire just now. If there were extra tokens in the queue for cin, they would eventually work their way through, and, after a series of error messages, eventually allow user input again. This is not the case here, though. I get an infinite number of error messages.
I have also tried the following, as a method of debugging:
1 2 3 4 5 6 7 8 9
|
//pre-define the string action:
action= "Hello, World!";
//then enter the loop:
do
{
cout << "What would you like to do?" << endl;
cin >> action;
//then test what has been inserted into the variable action:
cout << action << endl;
|
The output using this code is:
What would you like to do?
Hello, World!
Invalid input, please re-enter command
What would you like to do?
Hello, World!
Invalid input, please re-enter command
(this repeats infinitely)
|
So it appears that
cin >> action;
is being completely ignored by the program.