tr1/normal_distribution:没有这样的文件或目录

Mic*_* Gg 2 c++ gcc tr1 cmake

我正在尝试将TR1用于某些C++项目.不幸的是我收到错误,不明白为什么或如何正确地做到这一点!我在Linux下用gcc 4.4.5工作.

我收到了错误

myfile.cpp:21:35: error: tr1/normal_distribution: No such file or directory     
Run Code Online (Sandbox Code Playgroud)

我需要的TR1文件是通过以下方式导入的:

#include <tr1/normal_distribution>
Run Code Online (Sandbox Code Playgroud)

在CMakeLists.txt中我打开TR1支持(-std = c ++ 0x)

SET (CMAKE_CXX_FLAGS "-Wall -std=c++0x -DNDEBUG -O3 -march=nocona -msse4.2")  
Run Code Online (Sandbox Code Playgroud)

知道我做错了什么吗?

jua*_*nza 6

该标志-std=c++0x使您可以访问您的gcc版本中实现的任何c ++ 11功能.对于随机数分布,c ++ 11具有标题random.tr1使用c ++ 11时不需要命名空间.

tr1random 的版本在include中tr1/random,并且std::tr1名称空间下的所有内容都在其中.要访问它,您不需要该c++0x标志.

要明确:

对于TR1随机数:#include <tr1/random>并使用std::tr1::normal_distribution.

对于c ++ 11随机数:使用flag编译c++0x,然后#include <random>使用std::normal_distribution.