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

tr1/normal_distribution: No such file or directory

本文关键字:文件 normal distribution tr1      更新时间:2023-10-16

我正在尝试将TR1用于某些C++项目。不幸的是,我收到一个错误,不明白为什么或如何正确执行此操作!我正在使用 gcc 4.4.5 在 Linux 下工作。

我收到错误

myfile.cpp:21:35: error: tr1/normal_distribution: No such file or directory     

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

#include <tr1/normal_distribution>

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

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

知道我做错了什么吗?

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

随机的tr1版本在包含tr1/random,并且所有内容都在std::tr1命名空间下。要访问它,您不需要c++0x标志。

需要明确的是:

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

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

我相信它#include <random>.无论如何,检查一下。

尝试将

以下标志添加到 CMakeLists.txt上的 cxx:

set (CMAKE_CXX_FLAGS "-stdlib=libstdc++")

-std=c++0x不是必需