0

hi, i have this code:

#include<iostream>
#include<sstream>
#include<string>
using namespace std;
int main (char argc)
{
    string n1 = "141+246+3+64";
    int n2;
   	int pos = -1;	
    char toFind = '+';	
    do
    {		
         pos = n1.find(toFind, pos+1);	
         if(pos != -1)
         {
                stringstream(n1) >> n2;
                cout << n2 << endl;
                cout << n1 << endl;
                cout << pos << endl << endl;
                n1 = n1.substr(pos);
         }	
    } while( pos != -1 );
    system("pause");
}

this is the output: 141
141+246+3+64
3

246
246+3+64
5

Press any key to continue . . .

I dont know why it wont find all of the +'s. Any solutions?

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by thecoolman5
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.