CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2006
    Posts
    15

    Angry 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()?.

  2. #2
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: getline HELP pls

    what are the vars. 'park' and 'carindex' ? I mean. . are the initialized .. and how ?

  3. #3
    Join Date
    Oct 2006
    Posts
    15

    Re: getline HELP pls

    details park[200];
    int carindex;

  4. #4
    Join Date
    Jun 2002
    Location
    Stockholm, Sweden
    Posts
    1,641

    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

  5. #5
    Join Date
    Oct 2006
    Posts
    15

    Re: getline HELP pls

    Oh thx man

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured