I try to use getline after cin but the compiler ignore it and go directly to next input
int id , age ;
String name;
cin >> id;
getline (cin , name ) ;
cin >> age ;
I try to use getline after cin but the compiler ignore it and go directly to next input
int id , age ;
String name;
cin >> id;
getline (cin , name ) ;
cin >> age ;
The problem in your program is when you input the id and hit enter at runtime that space is considered as an input and stays in input buffer until you consume it. So, you need to consume that space. So it is easy to think that C++ compiler skips call to getline(cin,name)
function but it is actually not.
You can use cin.ignore() before getline .. as getline ends when it see \n in the stream .. and in cin instruction the user must press enter to end the input .. so the getline found it in buffer and the compiler will skip it .. so you must ignore it from stream
cin >> id;
cin.ignore(100,'\n');
getline(cin,name);