+ 5
How do inputs work in C++? [Solved]
When I enter inputs as 1 2 Abhay1 Abhay2 I get the following output, 1 2 2 2 Abhay1 Instead of 1 2 2 Abhay1 2 Abhay2 https://code.sololearn.com/cZ6E7P3Qt44r/?ref=app
2 ответов
+ 8
std::getline will consume the newline character which is registered in your input stream by std::cin (when you press enter). This is why a newline is being output instead of "Abhay2". You can use std::cin.ignore() after the last std::cin call, prior to entering the inner loop, to discard the newline in the input stream.
std::cout<<"Enter the number of lines follwing particular case";
std::cin>>N;
std::cin.ignore();
// ...
http://www.cplusplus.com/reference/istream/istream/ignore/
+ 3
Hatsy Rei ty very much!