Velocity Reviews

Velocity Reviews (
-   C++ (
-   -   getline(cin, string) (

goofolution 11-06-2006 04:23 AM

getline(cin, string)
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)
/* prompt user for input */
cout << " Supplier: ";
getline(cin, details.supplier);

cout << endl << " Date: ";

char option;
cout << endl << " Are the values you entered correct?" << endl << endl;
cout << " <y/n> ";
cin >> option;
if(option == 'y' || option == 'Y')
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.

goofolution 11-08-2006 04:03 AM

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?


supplier: someone
_ <--- program hangs here

All times are GMT. The time now is 11:58 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.