#include <iostream>
#include <cstdio>
#include <set>
#include <vector>
#include <map>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <cctype>
using namespace std;
int main()
{
//字符串转换成数字
/*
MORE: atoi(), atol();
*/
char s1[4] = "123";
double i = atof(s1);
printf("%lf\n", i);
/*
数字转换成字符串
itoa()函数有3个参数:第一个参数是要转换的数字,
第二个参数是要写入转换结果的目标字符串,
第三个参数是转移数字时所用的基数
MORE:
itoa() 将整型值转换为字符串
itoa() 将长整型值转换为字符串
ultoa() 将无符号长整型值转换为字符串
*/
int num = 100;
char str[25];
itoa(num, str, 10); //这里转换成了十进制
cout << str << endl;
cout << str[0] << endl;
return 0;
}
小总结:字符串和数字的简单相互转换
最新推荐文章于 2022-06-17 15:04:51 发布