一、int/long/float/double 转 字符串
方法1:itoa, ltoa(a表示array数组的意思) 头文件:stdlib.h 示例: int a = 3; long b = 23; char buf1[30] = "";
方法2:sprintf 头文件:stdio.h 示例: int a = 3;
方法3:ostringstream 头文件:#include <sstream> using namespace std; 示例: int a = 3;
二、字符串 转 int/long/float/double 方法1:atoi,atol,atof 头文件:stdlib.h 示例: int a = atoi("32"); long b = atol("333"); double c = atof("23.4");
方法2:strtol, strtod 头文件:stdlib.h 示例: long b = strtol("333", NULL, 10);//10表示十进制 double c = strtod("32.3", NULL); 方法3:sscanf 头文件:stdio.h 示例: int a;
方法4:istringstream 头文件:#include <sstream> using namespace std; 示例: int a; |