0

I would like to generate numbers with normal_distribution in c++11. Using Qt 4.8 MinGW. I have added the next line

QMAKE_CXXFLAGS += -std=c++0x

to my .pro file and then get next errors: 'swprintf::' has not been declared 'vswprintf::' has not been declared

ildjarn
  • 62,044
  • 9
  • 127
  • 211
kobra
  • 1,285
  • 2
  • 12
  • 15
  • "some_symbol has not been declared" probably means you're missing a header file, if it's happening during compilation. If it's happening during linking then you're probably missing a library. Can you post the full error message? – Seth Mar 10 '12 at 23:22
  • 2
    If you use `-std=c++0x`, then you should use `std::normal_distribution`. TR1 is a library for C++98! – Kerrek SB Mar 10 '12 at 23:22
  • Possible duplicate: http://stackoverflow.com/q/3445312/894321 – alexisdm Mar 11 '12 at 00:07
  • Please copy the errors using the clipboard. – Michael Burr Mar 11 '12 at 12:58

1 Answers1

2

TR1 really should be avoid when using C++11 as it was designed to meet the limitations of the previous standard. (also everything that was considered useful went on and became integrated into the standard.)

Luckily there is a comprehensive random number generation library in C++11 with normal distribution.

See here:

http://en.cppreference.com/w/cpp/numeric/random

#include <random>
:::
std::random_device rd;
std::normal_distribution<double> dist(0,99);
std::mt19937 engine(rd());
double a=dist(engine);

The exact error your getting look as though the particular implementation of TR1 isn't very good anyway. (missing include or missing namespace prefix).

111111
  • 15,686
  • 6
  • 47
  • 62