So I'm trying to make a calculator.
I'm doing it by parsing the strings of the operation the user inputted.
im doing it by adding spaces next(both left and right) of the operator(like "+")and using istringstream to divide the string to divide it.
for example, dividing "10+10" to '10', '+', '10' and change them to different datatypes and calculate them.

the thing is, if the user inputs smth like "10+10+10", i would need to declare another string for the extra addition operator and another double for the extra '10' at the end.

so what i want to ask is, how do i let C++ declare new strings and new variables when it needs on to store new stuf???

Recommended Answers

All 3 Replies

Could you post the code that you currently have?

A vector of strings comes to mind.

vector<string> stringStore;

Every time you need to add one, just add it to the end of the vector


Similarly for double values.


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.