#include <iostream>
#include <vector>
using std::cout; using std::cin; using std::endl; // sry for this :)
using std::vector; using std::string;
int main()
{
string input;
vector<int> iv;
vector<char> cv;
cout << "Type your calculations, example \"5+5\": ";
cin >> input;
for (auto c : input) {
if (isdigit(c)) {
iv.push_back(c);
}
elseif (ispunct(c)) {
cv.push_back(c);
}
}
if (cv[0] == '+') {
iv[0] += iv[1];
cout << iv[0]; // for some reason output is 106
}
return 0;
}
You are storing the character representation of the numbers in the vector not the actual integer representation. The reason why is because you aren't converting them to integers before you push them into the integer vector. So what it is doing is storing the decimal value of the character (Which is this case is 53 http://www.asciitable.com/ ) in the vector instead of the actual value. This is why you are getting such a large number as a result.
To remedy this you will need to convert the character representations to integer representations before you push them into the integer vector. This is quite easy with the new C++11 helper functions for this. Or if you want to do it the old fashion way you can use std::stringstream.