Centos7 g++ "to_string is not in a member of std"

Centos7 g++ "to_string is not in a member of std"

本文关键字:in member of std not is g++ to string Centos7      更新时间:2023-10-16

我有一些非常标准的C++代码,其中我使用to_string将 sting 和 int 一起添加,如下所示:

#include <string>
using namespace std;
class Color{
public:
int red, blue, green;
Color(int r, int g, int b){
red = r;
green = g;
blue = b;
}
string to_string(){
string color = "(" + std::to_string(red) + ", " + std::to_string(green) + ", " + std::to_string(blue) + ")";
return color;
}
string colorize(string text){
string styled = "33[38;2"+std::to_string(red)+";"+std::to_string(green)+";"+std::to_string(blue)+";177m"+"n"+text+"n"+"33[0m";
return styled;
}
};

当我尝试在 Centos7 上使用 g++ 编译它时,我收到错误"to_string不在 std 的成员中"。我需要做什么?为什么这不起作用? 我正在运行构建命令g++ main.cpp

我正在运行 gcc 版本 4.8.5

我相信您缺少的是编译器标志-std=c++11因为std::to_string是在C++11版本的标准中引入的。

在旧版本的 GCC 中,您可以将-std=c++0x用于 C++11 或-std=c++1y用于 C++14。