+ 1
[SOLVED]Why the output starting from . next iteration (next loop)
1 Réponse
+ 2
First call to `std::getline()` which was supposed to read value for <st>[0] doesn't read correctly because there is a left over '\n' character in the input stream.
The '\n' character was left over from the read in of values for variable <N> and <Q>.
std::cin >> N >> Q; // <- this line
Since `std::getline()` reads input until a '\n' was found; it assumed an empty line (consists of only '\n') was read in, and set <st>[0] as empty string.
To overcome this, you must clear the '\n' off the input stream by calling ignore() method from the `std::cin` object
std::cin.ignore();
Right after the line where you read value for <N> and <Q>.