getline(cin, string)

Joined
Nov 6, 2006
Messages
5
Reaction score
0
Hey all i've almost completed a fairly large project but am having some strange problems within one of my functions using getline(). After entering the first string the program skips over the rest of the input and prompts for supplier again.

Here's the function:

#include <iostream>
#include <string>
using namespace std;
...
...
...

int ConstantVariables(ShippingDetails &details)
{
while(1)
{
/* prompt user for input */
cout << " Supplier: ";
getline(cin, details.supplier);

cout << endl << " Date: ";
getline(cin, details.date);

char option;
cout << endl << " Are the values you entered correct?" << endl << endl;
cout << " <y/n> ";
cin >> option;
if(option == 'y' || option == 'Y')
break;
}
return 1;
}

The struct details contains strings supplier and date, along with some other which i have omitted as they do not cause the problem.

any help would eb appreciated.
 
Joined
Nov 6, 2006
Messages
5
Reaction score
0
ok so i checked around a bit more and the obvious solutoin is to add a getchar() at the beginning of the while loop, however i dont' like the fact that after entering the first string the cursor waits for another key stroke before moving to the next input. Is there any way to remove this?

eg.

supplier: someone
_ <--- program hangs here
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top