-
cin.get() ?
why is it that you cannot have 2 consecutive cin.get() for a char
in a row such as this:
(it skips the second prompt and just prints first name)
Code:
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
int main()
{
char nameF[40];
char nameL[40];
cout << "enter first name"<<endl;
cin.get(nameF,40);
cout << "enter first name"<<endl;
cin.get(nameL,40);
cout << nameF<< " " << nameL << endl;
return 0;
}
-
Try putting an cin.ignore() after the first cin.get()..
And btw. you wrote "enter first name" twice :D
Edit:
It might be the termination character from the first cin, that's ruins it for you.
Try reading this one:
http://www.cprogramming.com/tips/sho...ount=30&page=0
-
-
-
get() does not extract the delimiting char from the input stream (neither does >>). However, getline() does extract the delimiting char from the input stream.