数值转换为String(std::to_string)
2016-03-04 10:56
375 查看
std::to_string函数
Convert numerical value to string
Returns a string with the representation of val.
The format used is the same that printf would print for the corresponding type:
type of val printfequivalent description
Parameters
Example
Exceptions
The string constructor may throw.
string to_string (int val); string to_string (long val); string to_string (long long val); string to_string (unsigned val); string to_string (unsigned long val); string to_string (unsigned long long val); string to_string (float val); string to_string (double val); string to_string (long double val);
Convert numerical value to string
Returns a string with the representation of val.
The format used is the same that printf would print for the corresponding type:
type of val printfequivalent description
int "%d" Decimal-base representation of val. The representations of negative values are preceded with a minus sign (-). long "%ld long long "%lld unsigned "%u" Decimal-base representation of val. unsigned long "%lu unsigned long long "%llu float "%f" As many digits are written as needed to represent the integral part, followed by the decimal-point character and six decimal digits. inf (or infinity) is used to represent infinity. nan (followed by an optional sequence of characters) to represent NaNs (Not-a-Number). The representations of negative values are preceded with a minus sign (-). double "%f long double "%Lf
Parameters
val Numerical value. Return Value A string object containing the representation of val as a sequence of characters.
Example
// to_string example #include <iostream> // std::cout #include <string> // std::string, std::to_string int main () { std::string pi = "pi is " + std::to_string(3.1415926); std::string perfect = std::to_string(1+2+4+7+14) + " is a perfect number"; std::cout << pi << '\n'; std::cout << perfect << '\n'; return 0; } Edit & Run Possible output: pi is 3.141593 28 is a perfect number
Exceptions
The string constructor may throw.
相关文章推荐
- ECSHOP的订单状态在数据库中的表现
- DSP汇编"ZERO.L2 B0"机器码0427,如何解析?
- PHP调试
- Memcached实例
- Android - 文件读写操作 总结
- 实现自动匹配内容
- C++/MFC修行之路(7)MFC单文档程序调整客户区大小的方法
- 解决一个因Bitmap引起的OOM问题
- Solr技巧 -- 仿“竞价排名”
- android的数据存储方式------5种
- cocospod 安装和使用
- EasyUI Layout 布局
- PHP使用curl模拟post上传及接收文件的方法
- iOS开发 判断输入语言是否是汉语
- html笔试题
- 打包遇到错误:missing ios distribution signing identity for XXXXXXXXXX
- VS敲C++代码时遇到的Bug总结
- Java LinkedList双向链表源码分析
- API升级 PaddingStart 与 Padding End 过期解决办法
- 输入域名,localhost,直接跳转到controller的几种方式: