我想我以错误的方式使用了ATOI功能 . cout << endl <<“pch”<< pch“显示3为例,b = atoi(pch)在终端显示一个奇怪的符号,在调试器中显示”\ xcorrect number“ . (例如”\ x2“表示pch = 2) . 任何想法为什么?
类
void Complex::input(std::string& b)
{
char *pch;
pch = strtok(&b[0],"+ i");
if(pch!=NULL)
a=stoi(pch);
pch=strtok(NULL,"i +");
cout<<endl<<"pch"<<pch;
if(pch!=NULL)
b=stoi(pch);
cout<<endl<<"b"<<b;
};
主要()
int main()
{
Complex x, y;
std::string s1, s2;
std::cin>>s1;
std::cin>>s2;
x.input(s1);
y.input(s2);
Complex z = x + y;
std::cout << z << std::endl;
system("pause");
return 0;
}
该程序应添加两个复数 .