to_string不是std的成员,例如g+(Mingw)我正在做一个小的词汇记忆程序,在这个程序中,单词会随机地向我闪现以获取意义。正如BjarneStroustroup告诉我们的那样,我想使用标准C+库,但是我遇到了一个似乎很奇怪的问题。我想换一个long整数成std::string以便能够将其存储在文件中。我雇了to_string()同样的。问题是,当我用g+(如其-版本标志中提到的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'导致此错误的程序是:#include <string>int main(){
std::to_string(0);
return 0;}但是,我知道这不可能是因为MSDN库清楚地说它的存在先前的问题对于堆栈溢出(对于g+版本4.5),可以使用-std=c++0x旗子。我做错什么了?
3 回答
![?](http://img1.sycdn.imooc.com/54584ee0000179f302200220-100-100.jpg)
Smart猫小萌
TA贡献1911条经验 获得超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 关注
- 1835 浏览
添加回答
举报
0/150
提交
取消