View Single Post
Old 10-17-2004, 05:34 AM   #18 (permalink)
RobertStout
Registered User
 
RobertStout's Avatar
 
Join Date: Oct 2004
Location: Dank cellar
Posts: 18
RobertStout is on a distinguished road
I have encountered a problem when using std::getline

Here's a snippet..

Code:
/////////////////////////////
// Input name and finish time
for( int i = 0; i < RACERS; i++ )
{
cout << "Enter the name of racer #" << i+1 << ": ";
getline( cin, racers[i].sName );
cout << "Enter the finish time in minutes of racer #" << i+1 << ": ";
cin >> racers[i].iMinutes;
}
Quote:
Console Output..

Race Evaluator

Enter the name of racer #1: John H. Smith
Enter the finish time in minutes of racer #1: 103
Enter the name of racer #2: Enter the finish time in minutes of racer #2:
The problem is highlighted in red above. During the second for pass the program doesn't wait to accept the name input.
After googling my eyes out I can't fix it. Incorrect usage of cin in getline, right? Help would be appreciated.
RobertStout is offline   Reply With Quote