No Worky

This is a discussion on No Worky within the C++ Programming forums, part of the General Programming Boards category; I just put cin.get(); into my code and it isnt working so I tried to check this by putting in ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    545

    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
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,801
    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
    Posts
    545
    That is probably it...so ashould I jsut use cin.ignore after ever cin>> statement? Just incase I use cin.get();?

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    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:

    Simple question with the getline() function.

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, 10: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21