Hello, im making a console like math calculator and i cant seem to find a way to get the string input. it cuts the string.
also, how do i read the string "add 123 456 789" and give the answer? already did a basic one when i created functions that handle multiple numbers.
#include <iostream>
#include <string>
#include <sstream>
int main()
{
std::string line ;
std::getline( std::cin, line ) ; // read in a complete line
// enter "add 123 456 789"
// create an input stringstream which reads from the line
std::istringstream stm(line) ;
std::cout << "calculate: " << line << '\n' ;
// extract the command
std::string oper ;
stm >> oper ;
if( oper == "add" )
{
int result = 0 ;
int number ;
while( stm >> number ) // for each number read from line
result += number ;
std::cout << "result: " << result << '\n' ;
}
// else if( oper == "subtract" ) etc.
}