-1

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
  • 1
    Possible duplicate of [How to signify no more input for string ss in the loop while (cin >> ss)](https://stackoverflow.com/questions/5360129/how-to-signify-no-more-input-for-string-ss-in-the-loop-while-cin-ss) – Blastfurnace Jul 13 '17 at 02:38

1 Answers1

-1

you need to introduce a character to break the while loop once it is input?

Sunny Mok
  • 11
  • 1