[SOLVED]Why the output starting from . next iteration (next loop) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

[SOLVED]Why the output starting from . next iteration (next loop)

https://code.sololearn.com/cmpdhRAINOVl/?ref=app

30th Aug 2021, 5:30 PM
THE CRAZY ONE ✌️
THE CRAZY ONE ✌️ - avatar
1 Answer
+ 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>.
30th Aug 2021, 8:30 PM
Ipang