【最贴心】C++字符串转换(stoi;stol;stoul;stoll;stoull;stof;stod;stold)
生活随笔
收集整理的這篇文章主要介紹了
【最贴心】C++字符串转换(stoi;stol;stoul;stoll;stoull;stof;stod;stold)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
先說結(jié)論:
技巧:
在日常使用中, 最常用的是stoll和stod這兩個函數(shù), 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
如果這篇博文對你產(chǎn)生了幫助,可以留下小小的一個贊哦,大家的支持是我更新的最大動力~
總結(jié)
以上是生活随笔為你收集整理的【最贴心】C++字符串转换(stoi;stol;stoul;stoll;stoull;stof;stod;stold)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C语言满分代码:1018 锤子剪刀布 (
- 下一篇: DevC++最新汉化版(支持C++11)