I am trying to take multiple lines of input from the user with each line containing two numbers separated by a space:
4 7
15 21
32 78
My code so far is:
vector<string> lines;
string line;
int m, n;
while (true)
{
cin >> line;
if (line != "")
{
lines.push_back(line);
}
else
{
break;
}
}
for (string i: lines)
{
istringstream iss(i);
vector<string> results((istream_iterator<string>(iss)), istream_iterator<string>());
if (typeid(results[0]).name() == "char")
{
m = results[0] - '0';
}
else
{
m = atoi(results[0]);
}
if (typeid(results[1]).name() == "string")
{
n = results[1] - '0';
}
else
{
n = atoi(results[1]);
}
calculate(m, n);
}
I get an error at the m = results[0] - '0'
. It says
error: no match for 'operator-' (operand types are
'__gnu_cxx:__alloc_traits<std::allocator<std::__cxx11::basic_string<char> >
>::value_type {aka std::__cxx11::basic_string<char>}' and 'char')
Is there anyway to fix this so each number on each line is separated into an integer variable?