The problem is that stoi()
it will not work with char
. Alternatively you can use std::istringstream
for this. It also std::pow()
takes two arguments, the first of which is the base, and the second is a measure. Your comment says the square of the number is so ...
#include <sstream>
string s = "1 2 3 4 5 9 10 121";
istringstream iss(s);
string num;
while (iss >> num)
{
cout << pow(stoi(num), 2) << endl;
}
, , , s, for , 9.