I am trying to stop the loop when user gives a blank line, otherwise push name and score to a vector pair. But this code is not working.
Input format:
<name><score>
e.g.:
Akash 45
My code is below:
int m;
cin>>m;
vector<pair<string,int>>player;
string name;
int score;
while(1)
{
cin>>name;
if(name.empty())
break;
cin>>score;
player.push_back(make_pair(name,score));
}
Also , I have tried the following:
if(name.length()==0)
while(getline(cin,name))
if (name=="")
None of them worked.
Can anyone help me?