-
getline HELP pls
class details{
public:
char name[50];
char kind;
char carid[10];
char adress[20];
char date[8];
int cost;
};
void addcustomer(){
cout<<"Write name:";
cin.getline(park[carindex].name,50);
cout<<"Give the kind of membership(Press 't' for pre-paid memberships and 'n' for non pre-paid:";
cin>>park[carindex].kind;
cout<<"Arrival date(dd/mm/yy):";
cin>>park[carindex].date;
cout<<"Write car id:";
cin>>park[carindex].carid;
cout<<"Write the adress:";
cin.getline(park[carindex].adress,50);
carindex++;
}
When i try to run the addcustomer function then the compiler doesnt allow me to "Write name:" and it skips that stage, also the same with the adress. Is something go wrong with getline()?.
-
Re: getline HELP pls
what are the vars. 'park' and 'carindex' ? I mean. . are the initialized .. and how ?
-
Re: getline HELP pls
details park[200];
int carindex;
-
Re: getline HELP pls
It is because you have newline characters waiting in the stdin stream.
You have to ignore these!
Code:
cout<<"Write name:";
cin.ignore();
cin.getline(park[carindex].name,50);
More here:http://www.augustcouncil.com/~tgibso...al/iotips.html
-
Re: getline HELP pls