#having a problem again

1 messages · Page 1 of 1 (latest)

cosmic dock
#

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?

cosmic dock
cosmic dock
#

Hello?

quiet swift
#

Sorry, had no time to check your code yet

cosmic dock
#

What about now?

quiet swift
#

I'm working right now

obtuse ingot
#

easy fix

#

@

#

easy fix

patent snow
#

ill review it today

obtuse ingot
#

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?

fleet sedge
# cosmic dock in 59 line

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

quiet swift
#

Thanks for answering this @fleet sedge

cosmic dock
#

well, problem is, on my phone with std::cin.ignore()
everything is working, but in VS it is still ignored for some reason... weird

pallid plover
fleet sedge