Thread: cin.getline problem

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    45

    Unhappy cin.getline problem

    If I use the cin.getline(aString,int something)command the program runs well on the first time but if i restart the program by f.e. calling main for the second time, the program skips the cin.getline.
    What do I have to do to solve this problem?

  2. #2
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,227
    I was under the influence that calling main somewhere in your program was considered bad practice, anyhow.

    Otherwise, I'd suggest you need to flush out your input buffer ( ::dodges Hammer:: but not using fflush!! ). Just throw in an endl somewhere after you use cin.getline.

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    >>I was under the influence

    Been on that apple cider again Kendo

    He's right though....never call main() yourself

  4. #4
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Originally posted by -KEN-
    I was under the influence that calling main somewhere in your program was considered bad practice, anyhow.
    Yes, it even yields undefined behaviour.
    The function main shall not be used (3.2) within a program.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  5. #5
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    Posts
    362
    >f.e. calling main for the second time
    If you're allowed to do this then you're not using C++. Calling main recursively is illegal and results in a compile time error. It's allowed in C, but not a good idea.
    *Cela*

  6. #6
    terrance11
    Guest

    Re: cin.getline problem

    Originally posted by Ivan!
    If I use the cin.getline(aString,int something)command the program runs well on the first time but if i restart the program by f.e. calling main for the second time, the program skips the cin.getline.
    What do I have to do to solve this problem?
    getline(cin, string)

    should do the trick

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  2. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  3. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  4. Replies: 5
    Last Post: 11-07-2005, 11:34 PM
  5. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM