hi there,
im trying to using a new header file <random> from C++ Standard Library. I simply copy-paste the following example on http://www.cplusplus.com/reference/r..._distribution/
Code:
// bernoulli_distribution
#include <iostream>
#include <random>
int main() {
const int nrolls=10000;
std::default_random_engine generator;
std::bernoulli_distribution distribution(0.5);
int count=0; // count number of trues
for (int i=0; i<nrolls; ++i) if (distribution(generator)) ++count;
std::cout << "bernoulli_distribution (0.5) x 10000:" << std::endl;
std::cout << "true: " << count << std::endl;
std::cout << "false: " << nrolls-count << std::endl;
return 0;
}
Then I got the following errors after execution of the file "test.cpp" containing the code above:
Code:
g++ test.cpp
In file included from /usr/include/c++/4.4/random:35,
from test.c:3:
/usr/include/c++/4.4/c++0x_warning.h:31:2: error: #error 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.
test.cpp: In function ‘int main()’:
test.cpp:9: error: ‘default_random_engine’ is not a member of ‘std’
test.cpp:9: error: expected ‘;’ before ‘generator’
test.cpp:10: error: ‘bernoulli_distribution’ is not a member of ‘std’
test.cpp:10: error: expected ‘;’ before ‘distribution’
test.cpp:14: error: ‘generator’ was not declared in this scope
test.cpp:14: error: ‘distribution’ was not declared in this scope
I think the message on line 4 "...and must be enabled with the -std=c++0x or -std=gnu++0x compiler options." is important.
I´ve tried
Code:
sudo apt-get install linux-headers-`uname -r`
But that doesnt help. Apart from this I have to admit at this point that I have no idea what else to do here.
Anyone can tell me how to deal with it? Some command codes would be very nice
thank you very much!
best regards
Bookmarks