Thread: No Worky

  1. #1
    Registered User
    Join Date
    Nov 2005

    No Worky

    I just put cin.get(); into my code and it isnt working so I tried to check this by putting in system ("PAUSE") and it works fine with that...any reasons why it doesnt work?

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Northern Virginia/Washington DC Metropolitan Area
    Without any code to look at I will need to use my crystal ball to divine you an answer... Do you have any previous cin >> statements in your code before the point in which you attempt to call cin.get()? If so, then that's your answer. Add a second cin.get() call along with the first, either that or add a cin.ignore() call before the first cin.get().
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Nov 2005
    That is probably ashould I jsut use cin.ignore after ever cin>> statement? Just incase I use cin.get();?

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Or not use cin >> at all.
    Read everything into a buffer using getline, then parse the line using say a string stream.

    It's the same problem a C programmers face with mixing scanf() with say fgets(), then resorting to brain damage like fflush(stdin)

    Mixing input styles in either language generally leads to problems of one sort or another. IMO, it's best to separate the task of input from conversion.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    If you don't want to bother with remembering the intricacies of cin input and would rather focus on other programming challenges, consider using this:

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Mac - Default Lines Endings - fgets() - no worky
    By Dino in forum C Programming
    Replies: 6
    Last Post: 01-30-2008, 11:59 PM
  2. =( no worky.. help!
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 07-10-2002, 08:53 AM
  3. _beginthread when function has more than one parameter
    By blundstrom in forum C Programming
    Replies: 5
    Last Post: 10-04-2001, 12:28 PM