日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

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

發(fā)布時間:2024/1/1 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C++学习心得:字符串转换(to_string,stoi,stol,stoul) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

一、結(jié)論

使用C++11,并且導(dǎo)入頭文件?#include<string>

other ---> stringto_string (int / long / float /...)?
string --->otherstoistring 轉(zhuǎn) int
stolstring 轉(zhuǎn)long
stollstring 轉(zhuǎn) long long
stoulstring 轉(zhuǎn)?unsigned long
stoullstring 轉(zhuǎn) unsigned long long
stofstring 轉(zhuǎn) float
stodstring 轉(zhuǎn) double

?

?

?

?

?

?

?

?

注:在日常使用中, 最常用的是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

?

?

三、參考資料

[【最貼心】C++字符串轉(zhuǎn)換(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)

?

?

?

總結(jié)

以上是生活随笔為你收集整理的C++学习心得:字符串转换(to_string,stoi,stol,stoul)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。