Centos7 g++ "to_string is not in a member of std"
Centos7 g++ "to_string is not in a member of std"
我有一些非常标准的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。
相关文章:
- netcat command in c++
- Difference in displaying cv2 Mat
- C++ MFC Libraries in Travis CI
- Centos7 g++ "to_string is not in a member of std"
- C++ "Invalid use of 'this' in non-member function" ,
- 为什么我会收到此警告? "Member 'x' was not initialized in this constructor"
- 将数据添加到 CArray 会产生错误"cannot access private member declared in class 'CObject'"
- 错误:在 MacOS 上"no member named 'uint8_t' in the global namespace"
- "Member function must be called or its address taken in function" C++错误
- 错误"request for member 'nombreIntr' in 'jugadorActual'"
- 在C++中接收错误"member function must be called or its address taken in function"
- C++ substr 方法 - "invalid use of ‘this’ in non-member function"
- 数据"member not declared in this scope"
- 找到"cannot access private member declared in class 'QObject'"的根本原因
- 为什么我总是收到错误消息"no member named "令牌类型 " in 'Token"?
- "There is no "reference-to-member" type in C + +",std::bind 和 boost::bind 在同一条船上
- 如何在Xcode 4中摆脱"In class initializer for static data member ... is a C++0x extension"警告
- "In class member initialization"功能是否已制作成 C++11?
- 从Qt 5.6切换到Qt 5.7 - "no member 'make_unique' in namespace std"
- "error: request for member ‘size’ in ‘a’, which is of pointer type"但我不认为这是一个指针