I'm making a very simple program but unfortunately getline doesn't work.
The menu just send back the value of mnuOpt and does nothing with any other variable.
When I say getline doesn't work, I mean that it doesn't work. It won't let me input a damn thing.
It looks just like the compiler skips it completely.
I fixed it just now by placing a cin.ignore(num, '/n') and my case 1 looks like this:
I assume the buffer is full and that is why it couldn't get anymore input?
Right? Wrong?
I tried it with VC++ 6 and Dev C++ both have the same result.
Thanks
Code:
int main(void)
{
int mnuOpt=0;
char name[6];
mnuOpt = menu(mnuOpt);
switch(mnuOpt)
{
case 1:
cin.getline (name, 6);
break;
case 2:
return 0;
}
cout << name << endl;
system("pause");
return 0;
}
The menu just send back the value of mnuOpt and does nothing with any other variable.
When I say getline doesn't work, I mean that it doesn't work. It won't let me input a damn thing.
It looks just like the compiler skips it completely.
I fixed it just now by placing a cin.ignore(num, '/n') and my case 1 looks like this:
Code:
case 1:
cin.ignore(100,'\n');
cin.getline (name, 30);
break;
I assume the buffer is full and that is why it couldn't get anymore input?
Right? Wrong?
I tried it with VC++ 6 and Dev C++ both have the same result.
Thanks