課程
/后端開發(fā)
/C++
/C++遠征之封裝篇(上)
如標題所述。
2016-10-22
源自:C++遠征之封裝篇(上) 3-1
正在回答
使用stringstream對象簡化類型轉(zhuǎn)換
具體用法:
頭文件:#include <sstream>
stringstream ss;?????//定義流
string name = "lingdu"; ?//準備好的字符串
int c = name.size() ;????//size()返回一個int類型變量,將獲取到的整數(shù)給到變量c
ss << c;????//向流中傳值
string str;????//定義str,用于保存轉(zhuǎn)換后的string
ss >> str;????//將數(shù)據(jù)寫入到str
cout << str ?+ "ssss" << endl;????//此時完成int轉(zhuǎn)string
int aa = 30;
string s = boost::lexical_cast<string>(aa);
cout<<s<<endl; // 30
bc201 提問者
舉報
封裝--面向?qū)ο蟮幕?,本教程力求幫助小伙伴們即學即會
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學習伙伴
掃描二維碼關注慕課網(wǎng)微信公眾號
2016-10-23
使用stringstream對象簡化類型轉(zhuǎn)換
具體用法:
頭文件:#include <sstream>
stringstream ss;?????//定義流
string name = "lingdu"; ?//準備好的字符串
int c = name.size() ;????//size()返回一個int類型變量,將獲取到的整數(shù)給到變量c
ss << c;????//向流中傳值
string str;????//定義str,用于保存轉(zhuǎn)換后的string
ss >> str;????//將數(shù)據(jù)寫入到str
cout << str ?+ "ssss" << endl;????//此時完成int轉(zhuǎn)string
2016-10-22
int aa = 30;
string s = boost::lexical_cast<string>(aa);
cout<<s<<endl; // 30