错误信息:‘to_string’ is not a member of ‘std’

错误信息:‘to_string’ is not a member of ‘std’

作者:BlogUpdater |  时间:2018-04-18 |  浏览:7428 |  评论已关闭 条评论

问题程序

#include <string>
int main()
{
    std::to_string(0);
    return 0;
}

编译指令
# g++ main.cpp -o test

 

报告错误
error: ‘to_string’ is not a member of ‘std’

 

解决方法
添加-std=c++11 选项,如下所示
# g++ -std=c++11 main.cpp –o test

 

问题原因
to_string在新版本的C++11中才被支持,所以,这里在编译的时候添加了C++11的支持选项。

标签:

评论已关闭。