C ++ 11-- integer number string conversion

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/liangzhao_jay/article/details/87872493

C ++ 11 provides to_string, stoxxx method, the following sample code:

#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;
}

 

Guess you like

Origin blog.csdn.net/liangzhao_jay/article/details/87872493