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

海綿寶寶撒
TA貢獻1809條經驗 獲得超8個贊
#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 關注
- 443 瀏覽
添加回答
舉報
0/150
提交
取消