需要在c++中转换符号到dec

Need to convert symbol to dec in c++

本文关键字:符号 dec 转换 c++      更新时间:2023-10-16

使用类型强制转换将字符串转换为整数

string str="123456";
int buffer[str.length()];
for (int i=0; i<str.length();i++)
{
    buffer[i]=(int)str[i];
    cout << buffer[i];
}

得到以下结果495051525354符号123456

的DEC形式

但我想要"123456"作为结果。请帮助! !

我自己搞定了

string str="123456";
int buffer[str.length()];
for (int i=0; i<str.length();i++)
{
buffer[i]=(int)str[i] - 48;
cout << buffer[i];
}