mardi 22 mai 2018

When inputting strings for multiple test cases, why does it input null character for 1st test case and how to avoid it?

For any given question I have to take 't' test cases each a string. I have used the following code in c++ for the same:

{   int t;
cin>>t;
while(t--){
    string s;
    getline(cin, s);
    cout<<s;

}

Now the problem with the above code is that it takes a null character for the first test-case. Is there any way to avoid it?

Aucun commentaire:

Enregistrer un commentaire