#include #include #include //method: parse the string and create a vector of numbers and operators then iterate that vector to create the value int main(){ std::string str_val = "3*5+11+5*20+9*2*4+135"; std::vector expression; std::string number_holder; int position = 0; for (std::string::iterator it=str_val.begin(); it!=str_val.end(); ++it) { std::cout << "position: " << position << std::endl; position++; if(std::isdigit(*it)){ number_holder.push_back(*it); std::cout << "number is: " << number_holder << std::endl; } else{ //if the next char is not a number then its an operator expression.push_back(number_holder); number_holder = ""; std::cout << "operator is: " << *it << std::endl; std::string str(1, *it); expression.push_back(str); } } // There will always be a number as the last operand, so lets add it to the expression vector std::cout << "number is: " << number_holder << std::endl; expression.push_back(number_holder); // lets check the expression vector! TODO: delete this code segment, only for debuging //Great! Now lets while loop over the expression vector until its size == 1. int value = 0; //expression.size()>1 bool complete_multiplication = false; while(!complete_multiplication){ //view current expression std::cout << "expression" << std::endl; for(std::vector::iterator debug_it=expression.begin(); debug_it!=expression.end(); ++debug_it){ std::cout << *debug_it << std::endl; } for (unsigned i=0; i::iterator debug_it=expression.begin(); debug_it!=expression.end(); ++debug_it){ std::cout << *debug_it << std::endl; } for (unsigned i=0; i