Have problem accessing the poisson distribution template

I am using QT Creator 2.4.1 based on 4.7.4.

I wanted to generate a standard normal poisson distribution. So I used the template poisson distribution included in the header <random> by setting the value of mean to 0 and variance to 1.

I copied the entire example code for testing it but I get an error like "This file requires compiler and library support for the upcoming \
ISO C++ standard, C++0x. This support is currently experimental, and must be \
enabled with the -std=c++0x or -std=gnu++0x compiler options."

Is there anyone who could help me to sort this problem.
It tells you what to do right there. You just add those options when you compile. If you're using an IDE, go to the compiler settings and there should either be a list of available options that you choose, or somewhere where you can type in an option.

If from the command line, just add one of those flags when you go to compile.
In Qt those settings should go into your .pro file. Put this line into the file:

QMAKE_CXXFLAGS += -std=c++11 -Wall -Wextra -pedantic

I added some of the other flags I routinely use.

The setting for C++11 changed at some stage, the one I quoted should work for that version of gcc.


Edit: I am using Qt Creator 2.6.2 (Qt 5.0.1) which apparently has much better support for C++11.
Last edited on

I copied and kept the line what you said into the .pro file and its saying

error: unrecognized command line option "-std=c++11" .

Maybe the setting for c++11 changed as you said. Any suggestion??
Last edited on

Yes.. I have added
QMAKE_CXXFLAGS += -std=gnu++0x to the QMAKE file and that error was gone.

But still I have some errors
error: 'default_random_engine' was not declared in this scope
error: 'generator' was not declared in this scope

My code is :
#include <iostream>
#include <random>

using namespace std;
int main()
const int nrolls=10000; // number of experiments
const int nstars=100; // maximum number of stars to distribute

default_random_engine generator;
normal_distribution<double> distribution(5.0,2.0);

int p[10]={};

for (int i=0; i<nrolls; ++i) {
double number = distribution(generator);
if ((number>=0.0)&&(number<10.0)) ++p[int(number)];

cout << "normal_distribution (5.0,2.0):" << std::endl;

for (int i=0; i<10; ++i) {
cout << i << "-" << (i+1) << ": ";
cout << std::string(p[i]*nstars/nrolls,'*') << std::endl;

return 0;

even though I have used the same code as suggested by the example code in cplusplus.com under section normal_distribution.
Topic archived. No new replies allowed.