-1

While compiling the above code this is the error which i am getting.

 #include <random>
 #include <iostream>

int main()
{
  std::default_random_engine generator;
  std::uniform_int_distribution<int> distribution(1,6);
  int dice_roll = distribution(generator);  // generates number in the range 1..6   
}

In file included from /usr/include/c++/4.8/random:35:0, from fv.cpp:1: /usr/include/c++/4.8/bits/c++0x_warning.h:32:2: error: #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.

My gcc version is g++ (Ubuntu 4.8.2-19ubuntu1) 4.8.2

Please help me

Baum mit Augen
  • 49,044
  • 25
  • 144
  • 182
Ganesh Delli
  • 61
  • 1
  • 10
  • 2
    Try compiling with the flag `-std=c++11`. – Galik Sep 23 '14 at 23:19
  • 4
    Did you do what the error message says? – interjay Sep 23 '14 at 23:20
  • 1
    Did you try what the error message told you to do, adding `-std=c++11` to the compiler's command-line options? – Mike Seymour Sep 23 '14 at 23:20
  • 1
    If the above mentioned flag -std=c++11 doesn't work on compilation, try -std=c++0x. – davepmiller Sep 23 '14 at 23:27
  • @Ganesh Delli Are you using an IDE to develop with? Make? CMake? – davepmiller Sep 23 '14 at 23:30
  • 1
    @laser_wizard gcc 4.8 supports -std=c++11 – Baum mit Augen Sep 23 '14 at 23:30
  • 1
    possible duplicate of [Compiling C++11 with g++](http://stackoverflow.com/questions/10363646/compiling-c11-with-g) or [c++ - gcc 4.7 Give me error message](http://stackoverflow.com/questions/10108328/gcc-4-7-give-me-error-message) – Pixelchemist Sep 23 '14 at 23:32
  • I just pasted the error message in the question itself In file included from /usr/include/c++/4.8/random:35:0, from fv.cpp:1: /usr/include/c++/4.8/bits/c++0x_warning.h:32:2: error: #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. – Ganesh Delli Sep 23 '14 at 23:50
  • Possible duplicate of [Why random header not importing](https://stackoverflow.com/questions/31237259/why-random-header-not-importing) – Toby Speight Jul 17 '17 at 16:02

1 Answers1

3

This will compile fine after adding the -std=c++11 flag to your compilation command. This flag is needed to make gcc support c++11 features such as <random>.

If you compile in an terminal, just add the flag somewhere. If you use an IDE, you might have to change some option, but that does (of course) depend on your specific IDE.

Baum mit Augen
  • 49,044
  • 25
  • 144
  • 182