一、结论

使用C++11,并且导入头文件 #include<string>

other ---> string to_string (int / long / float /...)  
string --->other stoi string 转 int
stol string 转long
stoll string 转 long long
stoul string 转 unsigned long
stoull string 转 unsigned long long
stof string 转 float
stod string 转 double

注:在日常使用中, 最常用的是stoll和stod这两个函数, stoll可以兼容stoi,stol;  而stod可以兼容stof。

二、举例

1、stoll()

#include<iostream>
#include<string>
using namespace std;
int main() {string s = "11111";int a = stoll(s);cout << a;
return 0; }输出: 11111

2、stod()

#include<iostream>
#include<string>
using namespace std;
int main() {string s = "11.11";double a = stod(s);cout << a;
return 0; }输出:11.11

三、参考资料

[【最贴心】C++字符串转换(stoi;stol;stoul;stoll;stoull;stof;stod;stold)_来老铁干了这碗代码的博客-CSDN博客_stoul](https://blog.csdn.net/weixin_43899069/article/details/110290292?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-4&spm=1001.2101.3001.4242)

C++学习心得:字符串转换(to_string,stoi,stol,stoul)相关推荐

  1. c++字符串转换为数字(stoi, stol, stoul, stoull, stof, stod, stold)

    c++字符串转换为数字(stoi, stol, stoul, stoull, stof, stod, stold) 头文件#include <string> 1. stoi 将字符串转换成 ...

  2. std::stoi stol stoul stoll stof stod

    std::stoi stol stoul stoll stof stod 一系列函数为C++提供的转换string/wstring的方法,但是对于第二个参数网上说的是从第N个位置开始,其实并不是,不知 ...

  3. C语言学习笔记---字符串转换函数

    字符串转整数   字符串转换为整数的函数有两个,他们的函数原型如下: int __cdecl atoi(const char *_Str);long __cdecl atol(const char * ...

  4. C++字符串转换(stoi;stol;stoul;stoll;stoull;stof;stod;stold)

    一.stoi 头文件string int stoi (const string& str, size_t* idx = 0, int base = 10); int stoi (const w ...

  5. 一、软件界面的设计——QT设计师换背景,一些按钮学习心得,转换成py文件遇到的问题

    文章目录 前言 一.Qt设计师 1.使用部件 2.资源读入 二.转换成.py 1.转换工具 2.注意 前言 结合石油通信这门课,基于单片机课程.用了CC2530单片机,用了温湿度传感器,MQ-2传感器 ...

  6. python字符串转换字节_python 字节与字符串转换

    1.如果没有设置字符串编码格式,那么将采用系统默认编码格式 name = 'laogaoyang' # 采用系统默认编码格式 nameBytes = name.encode('utf-8') # 先将 ...

  7. oracle 转化为整数,字符串转换成整数——从源码学习

    字符串转换成整数:输入一个表示整数的字符串,把该字符串转换成整数并输出,例如输入字符串"345",则输出整数345. 在笔试面试中,atoi 即「字符串转换成整数」是一个经典问题了 ...

  8. openfoam学习心得--N-S方程无数种写法汇总与转换

    openfoam学习心得–N-S方程无数种写法汇总与转换以及守恒与非守恒型 在学习openfoam的途中,楼主被流体中存在的无数个方程.同一个方程无数种写法弄的晕头转向,决定对此做一些总结,方便以后查 ...

  9. Go 学习笔记(51)— Go 标准库之 strings(字符串比较、字符串前后缀、字符串统计、字符串索引、字符串包含、字符串转换、字符串复制、字符串替换、字符串去除、字符串分割和连接)

    1. 概述说明 import "strings" strings 包实现了用于操作字符的简单函数. strings 包与 bytes 包中的函数用法基本一样. 2. 主要函数 2. ...

最新文章

  1. 万字干货 | Python后台开发的高并发场景优化解决方案
  2. C++编程进阶8(最好不要实现类型转换运算符、单形参的构造函数与类型转换、临时对象与RVO)
  3. [数字图像处理]图像去噪初步(2)--非线性滤波器
  4. Linux下JNI实现
  5. Nuxt.js开发中碰到的问题(二)引入gitment评论系统
  6. git push error. ! [rejected] master - master (non-fast-forward)
  7. Qt学习(四):qt读写文件
  8. [CQOI2018] 交错序列(矩阵加速优化dp)
  9. [CCO 2019] Sirtet(差分约束+最短路)
  10. 剖析三大个人IM工具安全隐患
  11. loj2537 「PKUWC2018」Minimax 【概率 + 线段树合并】
  12. 2021年双十一大复盘:众人唱衰双十一,我们却发现了这些机会
  13. LeetCode之移除元素
  14. 是你渡过人生难关的助力_人工智能将助力安全返回工作场所。 这是如何做
  15. RoboWare Studio安装教程
  16. 485Modbus协议
  17. Matlab符号函数的生成及求符号函数的函数值
  18. html 操作cookie,HtmlUnit 模拟浏览器以及Cookie使用示例
  19. Powershell攻击指南1——PowerSploit
  20. pcode.linq

热门文章

  1. 计算机中的应用软件是指什么意思,为什么电脑上的软件称为软件,手机上的软件却叫做应用或者是APP?...
  2. 2017年7月17日 星期一 --出埃及记 Exodus 28:8
  3. web3j命令行工具
  4. git clone之后修改了东西 推到远程库去
  5. excel表格不够怎么添加_Excel表格技巧—无法自动求和怎么办
  6. 高中数学必修2知识点总结:第四章圆与方程
  7. 分享三款宝藏AI智能软件
  8. BAT大厂的架构大数据你有了解么?解析大数据技术及算法
  9. IT系统的组织架构体系设计(浅析金蝶EAS组织设计)
  10. 解码阿里数据:对外数据产品也浮出水面