Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Problem with cin.getline();

Reply
Thread Tools

Problem with cin.getline();

 
 
Poof
Guest
Posts: n/a
 
      07-11-2003
This is part of a database-kind-of program.

char name[50];
int age;

for(int x = 0; x < 2; x++)
{
cout << "Enter your name : ";
cin.getline(name, 50);
cout << "Enter your age : ";
cin >> age;
}

It runs fine the first time round the loop, but during its second run, it'll
skip the cin.getline part and go straight to "Enter your age : ";

So the output for the second run becomes
"Enter your name : Enter your age : "

It works fine if I use cin >> instead of cin.getline().... Anyone has any
idea?

Any responses are greatly appreciated!


 
Reply With Quote
 
 
 
 
Poof
Guest
Posts: n/a
 
      07-11-2003
Yikes really sorry here... Found out that you have to add a cin.ignore() to
clear the buffer


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem problem problem :( Need Help Mike ASP General 2 05-11-2004 08:36 AM



Advertisments