Centos7 g ++"to_string不在std的成员中" [英] Centos7 g++ "to_string is not in a member of std"

查看:84
本文介绍了Centos7 g ++"to_string不在std的成员中"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些非常标准的C ++代码,其中我使用 to_string 将字符串和整数加在一起,如下所示:

I have some pretty standard C++ code, in which I am using to_string to add a sting and an int together, like this:

#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 = "\033[38;2"+std::to_string(red)+";"+std::to_string(green)+";"+std::to_string(blue)+";177m"+"\n"+text+"\n"+"\033[0m";
        return styled;
    }

};

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

When I try to compile this using g++ on Centos7, I get the error "to_string is not in a member of std". What do I need to do? Why is this not working? I'm running the build command g++ main.cpp

我正在运行gcc版本4.8.5

I’m running gcc version 4.8.5

推荐答案

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

I believe what you are missing is a compiler flag -std=c++11 since std::to_string is introduced in C++11 version of the standard.

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

In the older versions of GCC you can use -std=c++0x for C++11 or -std=c++1y for C++14.

这篇关于Centos7 g ++"to_string不在std的成员中"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆