|
-
January 2nd, 2007, 08:33 AM
#1
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()?.
-
January 2nd, 2007, 09:02 AM
#2
Re: getline HELP pls
what are the vars. 'park' and 'carindex' ? I mean. . are the initialized .. and how ?
-
January 2nd, 2007, 09:12 AM
#3
Re: getline HELP pls
details park[200];
int carindex;
-
January 2nd, 2007, 09:41 AM
#4
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
Nobody cares how it works as long as it works
-
January 2nd, 2007, 09:49 AM
#5
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|