c++ 11字符串与string转换常用函数
这里主要介绍一下string to int 其他方法与这个类似,可到头文件 <string> 中查看
@_Str 转换的字符串
@_Idx 转换的长度(位数)
@_Base 进制
double stod(const string& _Str, size_t *_Idx = nullptr);float stof(const string& _Str, size_t *_Idx = nullptr);int stoi(const string& _Str, size_t *_Idx = nullptr, int _Base = 10);long stol(const string& _Str, size_t *_Idx = nullptr, int _Base = 10);long double stold(const string& _Str, size_t *_Idx = nullptr);unsigned long stoul(const string& _Str, size_t *_Idx = nullptr, int _Base = 10);long long stoll(const string& _Str, size_t *_Idx = nullptr, int _Base = 10);unsigned long long stoull(const string& _Str, size_t *_Idx = nullptr, int _Base = 10);
std::string y = "253647586946334221002101219955219971002";
int x; try {
x = stoi(y);
}
catch (std::invalid_argument&){
// if no conversion could be performed
cout << "Invalid_argument" << endl;
}
catch (std::out_of_range&){
// if the converted value would fall out of the range of the result type
// or if the underlying function (std::strtol or std::strtoull) sets errno
// to ERANGE.
cout << "Out of range" << endl;
}
catch (...) {
// everything else
cout << "Something else" << endl;
}
return 0;
string to_string(int _Val);string to_string(unsigned int _Val);string to_string(long _Val); stringto_string(unsigned long _Val);string to_string(long 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);
可以看到 to_string(); 方法不仅支持各种整型( 有符号的、无符号的、长的、短的 任意组合 ),还支持各种浮点型( float/double 包括长的、短的 )
c++ 11字符串与string转换常用函数的更多相关文章
- c++中string的常用函数说明
string可以说是是字符数组的升级版,使用更加啊方便,不容易出错.本文对string的常用函数进行简单介绍,做到会用即可. string中的常用函数分为四类,即赋值,添加,比较和删除. 一.赋值 1 ...
- C++string类常用函数
C++string类常用函数 string类的构造函数:string(const char *s); //用c字符串s初始化string(int n,char c); //用n个字符c初 ...
- Delphi字符串的基本操作与常用函数
参考:http://www.cnblogs.com/pchmonster/archive/2011/12/16/2290034.html 结合这个博客一起学习:http://www.cnblogs.c ...
- Kotlin——初级篇(八):关于字符串(String)常用操作汇总
在前面讲解Kotlin数据类型的时候,提到了字符串类型,当然关于其定义在前面的章节中已经讲解过了.对Kotlin中的数据类型不清楚的同学.请参考Kotlin--初级篇(三):数据类型详解这篇文章. 在 ...
- Kotlin——关于字符串(String)常用操作汇总
在前面讲解Kotlin数据类型的时候,提到了字符串类型,当然关于其定义在前面的章节中已经讲解过了.对Kotlin中的数据类型不清楚的同学.请参考Kotlin——初级篇(三):数据类型详解这篇文章. 在 ...
- C string.h 常用函数
参考:http://womendu.iteye.com/blog/1218155 http://blog.csdn.net/zccst/article/details/4294565 还有一些,忘记了 ...
- db2字符串截取方法及常用函数
select substr(index_code, 1, locate('-', index_code)-1) from report_data substr(str,m,n)表示从str中的m个字符 ...
- C语言字符,字符串,字节操作常用函数
strlen 这个函数是在 string.h 的头文件中定义的 它的函数原型是 size_t strlen( const char ); size_t 是一个无符号整型,是这样定义的 typedef ...
- JS中String,Math常用函数
String对象: 1.length属性 说明:获取字符串的长度 实例: var str="abc"; var i=str.length;//output:3 2.charAt() ...
随机推荐
- 扫描仪扫描文件处理-富士通ix500参数
纸张太薄不要扫,非常容易卡纸 当纸张薄的时候,每次不要放入太多,很容易因为层叠纸张压力导致滚动拉动单张力度过大,从而卡纸 卡纸第一时间叩开"滚轮盖" 去掉"自动跳过空白页 ...
- spring boot:thymeleaf模板中insert/include/replace三种引用fragment方式的区别(spring boot 2.3.3)
一,thymeleaf模板中insert/include/replace三种引用fragment方式的区别 insert: 把整个fragment(包括fragment的节点tag)插入到当前节点内部 ...
- centos7下面 es7.5 搭建
centos6 搭建 参考 https://www.cnblogs.com/php-linux/p/8758788.html 搭建linux虚拟机 https://www.cnblogs.com/ph ...
- php 注册器模式 工厂模式
<?php /** * 注册器模式 * 全局共享和交换对象 */ class Register { public static $objects; // 定义全局数组 // 保存对象到全局数组 ...
- PyTorch 中 weight decay 的设置
先介绍一下 Caffe 和 TensorFlow 中 weight decay 的设置: 在 Caffe 中, SolverParameter.weight_decay 可以作用于所有的可训练参数, ...
- Bitmap缩放(一)
使用矩阵进行压缩,通过缩放图片尺寸,来达到压缩图片的效果,和采样率的原理一样.先用位图的option将位图压缩一半,再用matrix缩放0.3f public class MainActivity e ...
- (Pixel2PixelGANs)Image-to-Image translation with conditional adversarial networks
Introduction 1. develop a common framework for all problems that are the task of predicting pixels f ...
- sqlServer数据库中的日期转换
今天开发过程中涉及到 sqlServer数据库数据同步至mysql数据,所以对日期格式转换需求,查到了一些关于sqlServer 的日期转换内容: 一般存入数据库中的时间格式为yyyy-mm-ddhh ...
- java Excel 自动调整列宽
在开发中经常需要用到对Excel文件的操作,现在根据网上的资料整理如下: import java.io.FileOutputStream; import org.apache.poi.hssf.use ...
- 面试时说Redis是单线程的,被喷惨了!
Redis是单线程的,这话搁以前,是横着走的,谁都知道的真理.现在不一样,Redis 变了.再说这句话,多少得有质疑的语气来跟你辩驳一番.意志不坚定的,可能就缴械投降,顺着别人走了. 到底是什么样的, ...