转载自:https://blog.csdn.net/liangzhao_jay/article/details/87872493
C++11提供了 to_string 、stoxxx方法, 示例代码如下:
#include <iostream>
#include <string>
using namespace std;
//数字转字符串
void numberTostr()
{
string strInt = std::to_string(100);
cout<<"strInt = "<<strInt<<endl;
}
//字符串转数字
void strToNum()
{
string strInt("100");
int num = std::stoi(strInt);
cout<<"num = "<<num<<endl;
}
int main()
{
numberTostr();
strToNum();
return 0;
}