I want to take the following format of input using scanf() until EOF that will avoid '+' sing and store only integer value. input sample:
1+2+8
output sample for the above input:
1 2 8
I wrote the following code for this:
while(scanf("%d+",&tmp)) //here 'tmp' is int type variable
{
v.push_back(tmp); //'v' is vector<int> type
}
for (int i = 0; i < v.size(); i++)
{
cout<<v[i]<<" ";
}
unfortunately while loop works as a infinite loop.What will be the solution for this problem?
Aucun commentaire:
Enregistrer un commentaire