I am getting data from a text file by using a for loop. I am trying to get all the operation in before the for loop ends.
The text file contains:
3
add 5 5
multiply 3
divide 2
My program looks like this
ifstream infile("test.txt.txt");
int number;
int first;
int second;
string command;
infile >> number;
cout<< number<<endl;
for (int i = 0; i < number;i++)
{
cout<<i<<endl;
infile >> command >> first >> second;
cout << command<<" "<<first<<" "<<second<<endl;
}
And the output I get is:
3
0
add 5 5
1
multiply 3 0
2
multiply 3 0
My question is on the last iteration, why didn't it input divide 2, and not multiply 3?
Best regards, Fre
Aucun commentaire:
Enregistrer un commentaire