本文共 565 字,大约阅读时间需要 1 分钟。
环境:dev-c++
源代码:
#include <iostream>
#include <cstdlib> using namespace std; main() { int i1=123,i2,i3; float f1; char c1[20]="234.45",c2[20]; string s1="456",s2; i2=atoi(c1); //将字符数组转化为整数 f1=atof(c1); //将字符数组转化为浮点型 itoa(i1,c2,10); //将整型转化为字符数组 10为10进制的意思 cout<<"字符数组转化为整型: "<<i2<<endl; cout<<"字符数组转化为浮点型: "<<f1<<endl; cout<<"整型转化为字符数组: "<<c2<<endl; strncpy(c2,s1.c_str(),s1.length());//字符串转化为字符数组 i3=atoi(c2); cout<<"字符串转化为整型: "<<i3<<endl; system("pause"); } 截图:
摘自
本文转自茄子_2008博客园博客,原文链接:http://www.cnblogs.com/xd502djj/archive/2012/03/09/2387742.html,如需转载请自行联系原作者。