Advertisement

Give me a hand on this one

Started by March 22, 2000 08:44 PM
3 comments, last by Choda 24 years, 7 months ago
can somebody tell me why this code doesnt work?: char job[30]; char background[50]; cout << endl << "Occupation?:"; cin.ignore(30, ''\n''); cin.getline(job, 30); cout << endl << "Now enter a brief description of your character:" <<endl; cin.ignore(50, ''\n''); cin.getline(background, 50); cout <<endl<< background; cout <<endl<< job; getch(); The first cin.getline seems to work, but the second one seems to mess up.... If a seasoned programmer could plug this into his\her compiler and give me some professional feedback, Id be very happy. Thanks
Arggggghh!!

Does anyone else find that its sometimes a bitch to paste code on gamedev? This is what it should have looked like....if this works..


char job[30];
char background[50];



cout << endl << "Occupation?:";
cin.ignore(30, ''\n'');
cin.getline(job, 30);

cout << endl << "Now enter a brief description of your character:" < cin.ignore(50, ''\n'');
cin.getline(background, 50);





cout < cout <
getch();

Sorry
Advertisement
ARRRRRGHHHHH!!!


I give up! Forget I even asked!!!!!!
If I understand correctly what you are trying to do, the following should work just fine!

#include
#include

int main()
{
char job[30];
char background[50];

clrscr();
cout << endl << "Occupation?:";
cin.getline(job, 30);
cout << endl << "Now enter a brief description of your character:";
cin.getline(background, 50);

cout << endl << endl << "Occupation: " << job << endl << "Description: " << background;

getch();

return 0;
}

Hope this helps!

..-=ViKtOr=-..
I am getting good at answering this specific question!

You must call cin.ignore() after EVERY cin.getline().
The ''\n'' is left in the buffer after you press return, so it needs to be cleared out.

This topic is closed to new replies.

Advertisement