头文件 :#include<string>
功能:将数字常量转换为字符串
参数:value
返回值:转换好的字符串
重载版本:
std::string to_string(int value); (1) (C++11起)
std::string to_string(long value); (2) (C++11起)
std::string to_string(long long value); (3) (C++11起)
std::string to_string(unsigned value); (4) (C++11起)
std::string to_string(unsigned long value); (5) (C++11起)
std::string to_string(unsigned long long value); (6) (C++11起)
std::string to_string(float value); (7) (C++11起)
std::string to_string(double value); (8) (C++11起)
std::string to_string(long double value); (9) (C++11起)
举例:
#include <iostream> // std::cout
#include <string> // std::string, std::to_string
using namespace std ;
int main()
{
std::string pi = "pi is " + std::to_string(3.1415926);
std::string perfect = std::to_string(1 + 2 + 4 + 7 + 14) + " this is a perfect number";
std::cout << pi << '\n';
std::cout << perfect << '\n';
system("pause");
}
————————————————
版权声明:本文为CSDN博主「Spielberg_1」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_18815817/article/details/82431685