0
for(int i=0;i<n;i++)
{
    string sen;
    cin.clear();
    cin.sync();
    cin.ignore();
    getline(cin,sen);
    cout<<" \n sen -> "<<sen<<endl;
}

this is my code.

Problem : when not adding cin.ignore(), getline(cin,sen) skips first input but after adding the cin.ignore(), after first input , the first character of every input it missing.

I viewed many post in stack overflow but didn't found the solution.

Input :

<tag1 value = "HelloWorld">
<tag2 name = "Name1">
</tag2>
</tag1>

output of current code :

 sen -> <tag1 value = "HelloWorld">

 sen -> tag2 name = "Name1">

 sen -> /tag2>

 sen -> /tag1>
Rnayak
  • 108
  • 11

0 Answers0