mardi 13 août 2019

getline is not working even with cin.ignore [duplicate]

getline is not working even with cin.ignore() function. it left some characters to read.

inputs:

3<br>
i will win<br>
will i<br>
today or tomorrow<br>
today or tomorrow and yesterday<br>
i dare you<br>
bad day<br>


    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL); 
        int t ,i , n;
        string alice , bob;
        cin>>t;//test cases
        while(t--)
        {
            cin.ignore();
            getline(cin,alice);
            getline(cin,bob);
            cin.ignore();
            cout<<alice<<endl<<bob<<endl;
        }
    }
    ````

expected result:

    -<br>
    i will win<br>
    will i<br>
    today or tomorrow<br>
    today or tomorrow and yesterday<br>
    i dare you<br>
    bad day<br>
    <br><br>
    actual result:-<br>
    i will win<br>
    will i<br>
    day or tomorrow<br>
    today or tomorrow and yesterday<br>
    dare you    &nbsp;&nbsp;&nbsp;  `<---i left in this`<br>
    bad day<br>

Aucun commentaire:

Enregistrer un commentaire