g_s(mingw)說to_string不是std的成員我正在制作一個(gè)小詞匯記憶程序,其中的單詞將隨機(jī)閃現(xiàn)在我的意思中。我想使用標(biāo)準(zhǔn)的C ++庫,就像Bjarne Stroustroup告訴我們的那樣,但我遇到了一個(gè)看似奇怪的問題。我想將long整數(shù)更改std::string為能夠?qū)⑵浯鎯υ谖募?。我也受雇于to_string()此。問題是,當(dāng)我使用g ++(版本4.7.0,如其--version標(biāo)志中所述)編譯它時(shí),它說: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'我的程序給出了這個(gè)錯(cuò)誤:#include <string>int main(){
std::to_string(0);
return 0;}但是,我知道它不可能是因?yàn)閙sdn庫清楚地說它存在并且早先關(guān)于Stack Overflow的問題(對于g ++版本4.5)說它可以用-std=c++0x旗標(biāo)打開。我究竟做錯(cuò)了什么?
3 回答

海綿寶寶撒
TA貢獻(xiàn)1809條經(jīng)驗(yàn) 獲得超8個(gè)贊
#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)注
- 436 瀏覽
添加回答
舉報(bào)
0/150
提交
取消