Have a look at this code. The issue the mention below.
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
string str;
getline(cin,str);//PROBLEM LINE let this line be (a)
cout<<str;
}
}
Input ->
1
With the above code it gets terminated without taking the string input.
IF I CHANGE THE LINE (a) with cin>>str the code runs fine
I/p 1
hello
O/p
hello
the loops runs t time but if the line (a) is getline(cin,str) the loop run t-1 times.
Can someone explain the problem why is this happening?