面对错误,我正尝试将char值转换为int,然后将它们平方。我尝试使用atoi()和sscanf(),但仍然遇到此错误
#include <stack>
#include<iostream>
#include<cmath>
#include<string>
#include <sstream>
using namespace std;
int main(){
int n;
std::cin>>n;
long long int num = n;
while(num != 1){
stack<char>s;
string strnum = to_string(num);
for(int i=0;i<strnum.size();i++){
s.push(strnum[i]);
}
num = 0;
while(!s.empty()){
int x=0;
//sscanf(s.top(),"%d",&x);
x = atoi(s.top());
num += (x*x);
std::cout << x << std::endl;
s.pop();
}
cout<<"num is : "<<num<<endl;
}
std::cout<<1;
}
面对错误,我试图将char值转换为int,然后将它们平方。我尝试使用atoi()和sscanf(),但仍然遇到此错误#include
此通话中