String s = \"1234\";
int result=0;
try
{
result=Integer.parseInt(s); //转换成整型
}
catch(Exception e)
{
throw new Exception(\"转换失败...\");
} #include <iostream>
using namespace std;
int main()
{
char *a=\"123\";
int i;
for(int j=0;j<3;j++)
{
int x=a;
x=x-48; //acsii码的转换
cout<<x<<endl;
}
return 0;
}
二楼的答案看不太明.因为没用过那些函数 atoi()这个函数作用是把一个字符串转换为整数。
其原型是:int atoi(char *s).
在stdlib.h中。
页:
[1]