#having a problem again
1 messages · Page 1 of 1 (latest)
Send your code
in 59 line
Hello?
Sorry, had no time to check your code yet
What about now?
I'm working right now
ill review it today
just from nothing the line with input just being ignored in first iteration and being triggered only on forward ones, what is it? and why the hell is it happening?
The issue lies on line 42.
On line 42, there is a sequence where you use std::cin to read a single character from the user and then attempt to read a line of input with std::getline on line 58. The problem is with how these two methods handle input.
When you use std::cin >> ans; on line 42, it reads characters from the standard input until it encounters whitespace (like a newline).
On line 42, you enter 'Y' and hits Enter, the input buffer still contains the newline character (The Enter key press). This newline character is the problem, because when you subsequently call std::getline(std::cin, ans); on line 58, it tries to read from the input buffer starting from the current position. Because the previous std::cin call left a newline in the buffer, std::getline reads this newline as an empty string. One way to fix this is to use std::cin.ignore() after using std::cin
Thanks for answering this @fleet sedge
thanks, good to know
well, problem is, on my phone with std::cin.ignore()
everything is working, but in VS it is still ignored for some reason... weird
you might have to ignore more than one character
I think you are entering the validation input while loop on line 44. There is no std::cin.ignore() under the std::cin on line 47. If that's not the problem, then Idk.
