Problems with std::cin

Well I was working on a code and I have a menu configured so the user can choose from the different options that there are. But apparently the program overlooks the std::getline() that go after that part :S

Well I was working on a code and I have a menu configured so the
user can choose from the different options that there are. But
apparently the program overlooks the std::getline() that go after that
part :S

Here is what I’m doing:
int main(int argc, char **argv)
{
unsigned int muiOption = 0;
std::string mszString;

do{

std::cout < < “Main Menu” << std::endl;
/*The options are included here*/
std::cout << “Option: “;
std::cin >> muiOption;

switch(muiOption){
case 1:
std::cout < < “Write a string of text: “;
std::getline(std::cin, mszString);
std::cout << “You typed: ” << mszString << std::endl;
break;
case 2:

}
}while(mszOption != 3);
return 0;
}

Now, when the user selects an option other than 3, the code simply
skips the std::getline() and it prints the std::cout that are there. So
the output looks like this:

Main Menu
[Options are printed here]
Option: 1
Write a string of text: You typed:
Main Menu
[Options are printed here]
Option:

so what could I be doing wrong? Can anyone tell me?

The code can be downloaded from http://lexington.opencurve.org/~lmurillo/p3.cpp
There are two required files, in case you want to compile the code:
http://lexington.opencurve.org/~lmurillo/lista.cpp
http://lexington.opencurve.org/~lmurillo/lista.h

[NOTE: Parts of the code are in spanish and other parts are in english]

-LMurillo

0 Responses to “Problems with std::cin”


  1. No Comments

Leave a Reply