hi, I am trying to make a calculator and I need the stringstream function to convert a a certain part of a string.

string n1 = "243+79";
int n2 = 0;
stringstream(n1[0-2]) >> n2; // this converts the 243 from n1 to an int

Any solutions?

Edited 5 Years Ago by thecoolman5: n/a

std::string asd="234+34";
   char plus;
   int first,second;
   std::stringstream (asd) >> first >> plus >> second;

Also, i need a function that can remove parts of a string.

That's what the substr() function does.

string n1 = "243+79";
    string first = n1.substr(0,3);
    string second = n1.substr(4,2);

In other words string.substr(starting_index, number_of_characters);

This question has already been answered. Start a new discussion instead.