一、转换函数
stoi(): 字符串转换为 int
stol(): 字符串转换为 long
stoll(): 字符串转换为 long long
stof(): 字符串转换为 float
stod(): 字符串转换为 double
to_string(): 整形或浮点型转换为字符串
二、举个栗子
1、
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char ** argv)
{
string a = "123";
string b = "123.4";
int c = stoi(a);
float d = stof(b);
string e = to_string(c);
cout << c << endl;
cout << d << endl;
cout << e << endl;
return 0;
}
三、_End
1