-1

I'm using Code::Blocks 13.12 GNU GCC Compiler and when I attempt to compile:

#include <iostream>
#include <array>
#include <iomanip>

using namespace std;

int main()
{
    array< int, 20 > c1={};
    array< int, 20 > c2={};
    array< int, 20 > c3={};
}

It jumps to a header file "c++0x_warning.h" with the following warning:

#ifndef _CXX0X_WARNING_H
#define _CXX0X_WARNING_H 1

#ifndef __GXX_EXPERIMENTAL_CXX0X__
#error This file requires compiler and library support for the \
ISO C++ 2011 standard. This support is currently experimental, and must be \
enabled with the -std=c++11 or -std=gnu++11 compiler options.
#endif
#endif

What am I doing wrong? Sorry I just started studying C++ and I couldn't find any useful info when googling this issue.

Titan552
  • 39
  • 2
  • 8
  • CodeBlocks is an IDE, not a compiler. GCC is a compiler. It sounds like you are using an old version of GCC. As well as passing `-std=c++11` as suggested by ShadowRanger's answer, it would be a good idea to install a later version of gcc, e.g. [here](http://www.mingw-w64.org/) – M.M Jan 21 '16 at 05:47

1 Answers1

3

Read the error message, it's telling you the exact problem. You need to pass -std=c++11 or -std=gnu++11 as a compiler argument to use std::array, which was only introduced with the C++11 standard. A later standard supported by your compiler (e.g. -std=c++14) would also work.

For the specific case of CodeBlocks, enabling C++11 support has been asked and answered: How can I add C++11 support to Code::Blocks compiler?

Community
  • 1
  • 1
ShadowRanger
  • 143,180
  • 12
  • 188
  • 271
  • How do I pass -std=c++11? Where does it go in the code? Or is it added somewhere else? – Titan552 Jan 21 '16 at 18:49
  • @Titan552: It's a command line flag to `gcc`/`g++`; CodeBlocks is hiding the details of your compilation from you (it's a good idea to get a basic idea of how you'd manually invoke a compiler BTW; IDE build support is a crutch that's best to avoid until you understand the basics of compiling and linking so you can understand what's going on when stuff goes wrong). In any event, for CodeBlocks, someone already asked this question: [How can I add C++11 support to Code::Blocks compiler?](http://stackoverflow.com/q/18174988/364696) Added same link to answer for completeness. – ShadowRanger Jan 21 '16 at 19:43