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?
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 ...
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?
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().
I used to be an adventurer like you... then I took an arrow to the knee.
That is probably it...so ashould I jsut use cin.ignore after ever cin>> statement? Just incase I use cin.get();?
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.
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.