C++11中的to_string

C++11之前,标准库没有提供数字类型转字符串的函数,需要借助sprintf、stringstream等,现在C++11提供了std::to_string函数,可以直接使用了:

点击(此处)折叠或打开

  1. string to_string (int val);
  2. string to_string (long val);
  3. string to_string (long long val);
  4. string to_string (unsigned val);
  5. string to_string (unsigned long val);
  6. string to_string (unsigned long long val);
  7. string to_string (float val);
  8. string to_string (double val);
  9. string to_string (long double val);

​除此之外,C++11标准库还引入了字符串转整数系列函数:

点击(此处)折叠或打开

  1. int stoi (const string& str, size_t* idx = 0, int base = 10);
  2. long stol (const string& str, size_t* idx = 0, int base = 10);
  3. long long stoll (const string& str, size_t* idx = 0, int base = 10);
  4. unsigned long stoul (const string& str, size_t* idx = 0, int base = 10);
  5. unsigned long long stoull (const string& str, size_t* idx = 0, int base = 10);
  6. double stod (const string& str, size_t* idx = 0);
  7. float stof (const string& str, size_t* idx = 0);



转载于:https://www.cnblogs.com/aquester/p/9891595.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值