I am trying to print inputs until user gives a blank input.So,I used getline(cin,input).But,When i use getline(cin,input).It is skipping first input while giving output.
#include <iostream>
using namespace std;
int main() {
while(1)
{
string n;
getline(cin, n);
while(getline(cin,n) && !n.empty())
{
cout<<n<<endl;;
}
if(n.empty())
break;
}
return 0;
}
sample input:
12 2
output obtained:
2
output needed:
12 2
Aucun commentaire:
Enregistrer un commentaire