1、to_string
包含在# include<string>。作用是把数值类型如int、double、long等转化为string,详细可参考博客:https://blog.csdn.net/lzuacm/article/details/52704931
int a = 4;
double b = 3.14;
string str1, str2;
str1 = to_string(a);
str2 = to_string(b);
cout << str1 << endl;
cout << str2 << endl;
2、stoi和atoi
包含在#include<string>,不是c++11的可以在#include<cstring>。作用是将字符串转化为int型。区别是stoi的形参是const string*,而atoi的形参是const char*。c_str()的作用是将const string*转化为const char*。
string s1("1234567");
char* s2 = "1234567";
int a = stoi(s1);
int b = atoi(s2);
int c = atoi(s1.c_str());
cout << a << endl;
cout << b << endl;
cout << c << endl;