I wrote a program in c++ that should split a string into a vector using spaces.
Right now what the while loop is doing is that it reads the whole strong i put in but it doesn't break out once it is done.
How do I make it break out of the loop once it is done reading?
p.s: I print the size everytime it ran through the loop and that's how I found out that it went through all the individual numbers in the string
int main()
{
vector<string> postfix;
double result;
cout << "Please enter the postfix equation that you want to evaluate Note: it can not be empty!\n";
vector<string> expression;
string token;
while (cin >> token)
{
expression.push_back(token);
cout <<expression.size()<<endl;
}
postfix = expression;
evaluatePostfix(postfix,result);
cout <<"End"<<endl;
}
This is a sample of what I am currently getting:
Please enter the postfix equation that you want to evaluate Note: it can not
be empty!
6 9 7 1 2
1
2
3
4
5