C++ 未找到文件:在C+;中使用数组类+;

C++ 未找到文件:在C+;中使用数组类+;,c++,compiler-errors,C++,Compiler Errors,下面是代码:main.hpp的第8行显示错误 //main.hpp #ifndef MAIN_HPP // if main.hpp hasn't been included yet... #define MAIN_HPP // #define this so the compiler knows it has been included #include <array> // OFFENDING LINE 8 using std:array class Quickso

下面是代码:main.hpp的第8行显示错误

//main.hpp
#ifndef MAIN_HPP  // if main.hpp hasn't been included yet...
#define MAIN_HPP //   #define this so the compiler knows it has been included  

#include <array> // OFFENDING LINE 8
using std:array


class Quicksort {

public:
  void sort(array);

};

#endif 
}

为什么我会犯这个错误?我认为我的C++和G++是好的。它可能不起作用的任何其他原因

我使用命令(在Mac上,使用最新的X代码)进行编译:g++版本4.2 g++-Wall-c quicksort.cpp

当我使用-std=c++11时,它会说:
无法识别的命令行选项“-std=c++11”

您需要c++11支持才能包含
。在GCC上,您需要使用
-std=c++0x
标志(或在最新版本上使用-std=c++11)。 此外,
array
位于
std
命名空间中,您可能想传递一个引用:

void sort(std::array&);
如果编译器不支持C++11的相关部分,则可以使用TR1的版本:

#include <tr1/array>

...
std::tr1::array<int, 5> a = ...;
#包括
...
std::tr1::数组a=。。。;

您忘记在4.7.0之前的GCC旧版本中包含
-std=c++11
-std=gnu++11
-std=c++0x
-std=gnu++0x
),后者包含扩展。如果这仍然不起作用,那么您需要更新版本的GCC。

您可能需要
-std=c++11
。GCC4.2已有5年历史,它不支持c++11。安装较新的GCC或使用Clang和libc++有更新的方法吗?如果我在Mac上,我会诚实地得到Clang。由于许可问题,苹果不会提供任何比GCC 4.2更新的产品,因此您需要自己安装,例如,自制
#include <tr1/array>

...
std::tr1::array<int, 5> a = ...;