- Sep 4, 2000
- 482
- 0
- 0
I fixed the following by getting a string and getting the first char of the string... still is there a way to flush cin if I wanted to?
Also does anyone know of a good string tokenizer for c++ ? I like to input a bunch of numbers on a line and string tokenize it..
===========================================
I have the following code, which is supposed to get a line
and stick it in a string. There's a basic menu before this
that cin's a char to choose a menu option. What happens is I have to input the string twice or else it doesn't get anything at all. Does the cin of a char leave the rest of the input to muck up any other input? Or is there a way to flush cin so it doesn't keep stuff around?
the main menu inputs a char and then does something like:
switch(charChoice){
case 'h':
printMenu();
break;
case 'a':
addEntry();
break;
void addABunch() {
cout << ("Gimme a bunch of numbers : "
;
string input;
getline(cin,input);
getline(cin,input); // had to do it twice...
cout << "You gave me : " << input << "\n";
}
Also does anyone know of a good string tokenizer for c++ ? I like to input a bunch of numbers on a line and string tokenize it..
===========================================
I have the following code, which is supposed to get a line
and stick it in a string. There's a basic menu before this
that cin's a char to choose a menu option. What happens is I have to input the string twice or else it doesn't get anything at all. Does the cin of a char leave the rest of the input to muck up any other input? Or is there a way to flush cin so it doesn't keep stuff around?
the main menu inputs a char and then does something like:
switch(charChoice){
case 'h':
printMenu();
break;
case 'a':
addEntry();
break;
void addABunch() {
cout << ("Gimme a bunch of numbers : "
string input;
getline(cin,input);
getline(cin,input); // had to do it twice...
cout << "You gave me : " << input << "\n";
}