-
help with cin.getline()
Hi there good people.
Ok i'm puzzled, i got his as my main(), but I defined other functions b4 (just for the record, since believe that they have no influence whatsoever in what's happening)
int main()
{
int escolha;
char txt[1000];
cout<<"O APONTADOR DE HISTORIAS"<<endl;
menuprint();
cin>>escolha;
if (escolha == 1)
{
cin.getline(txt, 1000, '\n');
//does some other stuff.....
return 0;
}
}
my problem is the program doesn't stop at cin.getline(....) as spouzed, and read the input. This looks pretty straight forward to me, that's why it puzzles me even more. All the #includes are present.
So if somebody could please clear me out on this matter, i would be ever so much appreciated.
thankxx in advance for your kind attention.
1976
PS - in case you're wondering what language is in between quotes it's Portuguese
-
The statement -
cin>>escolha;
is leaving a '\n' in the buffer which is then being picked up by getline causing it to terminate immeadiately. If you put
cin.ignore(80,'\n');
after cin>>escolha; then it will remove any stray input and the newline.