std::to_string
来自cppreference.com
< cpp | string | basic string
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <string> 中定义
|
||
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 起) |
1)
有符号十进制整数转换为字符串内容相同的std::sprintf(buf, "%d", value)会产生足够大的
buf
.原文:
Converts a signed decimal integer to a string with the same content as what std::sprintf(buf, "%d", value) would produce for sufficiently large
buf
.2)
有符号十进制整数转换为字符串内容相同的std::sprintf(buf, "%ld", value)会产生足够大的
buf
..原文:
Converts a signed decimal integer to a string with the same content as what std::sprintf(buf, "%ld", value) would produce for sufficiently large
buf
..3)
有符号十进制整数转换为字符串内容相同的std::sprintf(buf, "%lld", value)会产生足够大的
buf
.原文:
Converts a signed decimal integer to a string with the same content as what std::sprintf(buf, "%lld", value) would produce for sufficiently large
buf
.4)
std::sprintf(buf, "%u", value)会产生足够大的
buf
了同样内容的一个字符串转换成一个无符号十进制整数.原文:
Converts an unsigned decimal integer to a string with the same content as what std::sprintf(buf, "%u", value) would produce for sufficiently large
buf
.5)
std::sprintf(buf, "%lu", value)会产生足够大的
buf
了同样内容的一个字符串转换成一个无符号十进制整数.原文:
Converts an unsigned decimal integer to a string with the same content as what std::sprintf(buf, "%lu", value) would produce for sufficiently large
buf
.6)
std::sprintf(buf, "%llu", value)会产生足够大的
buf
了同样内容的一个字符串转换成一个无符号十进制整数.原文:
Converts an unsigned decimal integer to a string with the same content as what std::sprintf(buf, "%llu", value) would produce for sufficiently large
buf
.@ 7,8 @std::sprintf(buf, "%f", value)会产生足够大的
buf
了同样内容的一个字符串转换成一个浮点值.原文:
@7,8@ Converts a floating point value to a string with the same content as what std::sprintf(buf, "%f", value) would produce for sufficiently large
buf
.9)
std::sprintf(buf, "%Lf", value)会产生足够大的
buf
了同样内容的一个字符串转换成一个浮点值.原文:
Converts a floating point value to a string with the same content as what std::sprintf(buf, "%Lf", value) would produce for sufficiently large
buf
.目录 |
[编辑] 参数
value | - | 一个数值转换
|
[编辑] 返回值
一个字符串保持转换后的值
[编辑] 示例
#include <iostream> #include <string> int main() { double f = 23.43; std::string f_str = std::to_string(f); std::cout << f_str << '\n'; }
输出:
23.430000
[编辑] 另请参阅
(C++11) |
到 wstring 转换为整数或浮点值 原文: converts an integral or floating point value to wstring (函数) |