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?
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?
You can also think about strtol
as a way to parse known good input.
Also, i need a function that can remove parts of a string.
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);
Ok thanks for the help.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.