How to add or subtract the value of string? For example:
std::string number_string;
std::string total;
cout << "Enter value to add";
std::getline(std::cin, number_string;
total = number_string + number_string;
cout << total;
This just append the string so this won’t work. I know I can use int data type but I need to use string.
You can use
atoi(number_string.c_str())to convert the string to an integer.If you are concerned about properly handling non-numeric input,
strtolis a better choice, albeit a little more wordy. http://www.cplusplus.com/reference/cstdlib/strtol/