to_string不是std的成員,例如g+(Mingw)我正在做一個小的詞匯記憶程序,在這個程序中,單詞會隨機地向我閃現(xiàn)以獲取意義。正如BjarneStroustroup告訴我們的那樣,我想使用標(biāo)準(zhǔn)C+庫,但是我遇到了一個似乎很奇怪的問題。我想換一個long整數(shù)成std::string以便能夠?qū)⑵浯鎯υ谖募小N夜土藅o_string()同樣的。問題是,當(dāng)我用g+(如其-?版本標(biāo)志中提到的4.7.0版本)編譯它時,它說:PS C:\Users\Anurag\SkyDrive\College\Programs> g++ -std=c++0x ttd.cpp
ttd.cpp: In function 'int main()':ttd.cpp:11:2: error: 'to_string' is not a member of 'std'導(dǎo)致此錯誤的程序是:#include <string>int main(){
std::to_string(0);
return 0;}但是,我知道這不可能是因為MSDN庫清楚地說它的存在先前的問題對于堆棧溢出(對于g+版本4.5),可以使用-std=c++0x旗子。我做錯什么了?
3 回答

Smart貓小萌
TA貢獻1911條經(jīng)驗 獲得超7個贊
#include <string>#include <sstream>namespace patch{ template < typename T > std::string to_string( const T& n ) { std::ostringstream stm ; stm << n ; return stm.str() ; }}#include <iostream>int main(){ std::cout << patch::to_string(1234) << '\n' << patch::to_string(1234.56) << '\n' ;}
#include <sstream>
- 3 回答
- 0 關(guān)注
- 1878 瀏覽
添加回答
舉報
0/150
提交
取消