c++ 0x: uniform_real_distribution不是std的成员
C++0x: uniform_real_distribution is not a member of std
我正在尝试使用c++0x编译我的第一段代码。我很擅长c++,但是这个问题难倒了我。以下代码将无法编译:
#include <iostream>
#include <random>
int main()
{
unsigned seed = 12345;
std::mt19937 generator(seed);
std::uniform_real_distribution<double> distro1(0.0, 1.0);
for (unsigned int i = 0; i < 25; i++)
{
std::cout << "Help" << std::endl;
std::cout << "Value == " << distro1(generator) << std::endl;
}
}
我用下面的代码编译:
g++ -std=c++0x myFile.cpp or with g++ -std=gnu++0x myFile.cpp
我得到的错误是:
myFile.cpp: In function ‘int main()’:
myFile.cpp:11: error: ‘uniform_real_distribution’ is not a member of ‘std’
myFile.cpp:11: error: expected primary-expression before ‘double’
myFile.cpp:11: error: expected ‘;’ before ‘double’
myFile.cpp:15: error: ‘distro1’ was not declared in this scope
g++是:g++ --version
g++ (Debian 4.4.5-8) 4.4.5
奇怪的是,它编译过去的mt19937实例化,如果我只是调用mt19937::operator()
,我得到预期的输出。此外,如果我将发行版切换为normal_distribution,它会编译并输出"帮助"行,但不会做任何其他事情。可以看到该进程通过ps aux
运行,但没有输出。
我错过了什么愚蠢的东西吗?我基本上是从cplusplus.com复制代码来显示一个mwe。谢谢你的帮助
您必须升级到更高版本的编译器(您的程序在GCC 4.7.2上编译得很好)。GCC 4.4.5附带的标准库的实现显然不(完全)与c++ 11兼容。
相关文章:
- 为什么我应该在异常处理中使用std::cerr而不是std::cout
- std::to_string - 'to_string' 不是 'std' 的成员 - Visual Studio Code 1.42.0
- FreeFileSync C++错误:'byte'不是 'std' 的成员
- 使用 std::addressof(std::cout) 而不是 &std::cout 是否有任何风险?
- 隐式转换为比较函数对象(函子)用于 std::sort 而不是 std::map?
- 无法从好友功能访问类的私有成员?"ostream"不是"std"的成员?
- 线程不是 std c++ 的成员
- 为什么会出现错误:size不是std的成员
- 读取互斥对象范围之外的volatile变量,而不是std::atomic
- 不是 'std::vector<_Ty> 的成员
- C++ GCC 错误:"sqrtl"不是"std"的成员
- _Pairib":不是"std::map,std::分配器"的成员>>
- 如何将 std::list of 派生类而不是 std::list of parent class 传递给函数
- 'make_unique'不是'std'的成员
- "random_shuffle":不是"std"错误的成员
- 为什么错误:"locate_zone"不是"std::chrono"的成员
- 为什么 std::when_any 使用 std::tuple 而不是 std::vector 作为其结果类型?
- "<某些系统标头>:错误:"<在此处插入函数>"在移动源文件后不是"std"的成员
- Clang希望我写:: STD :: Declval而不是STD :: Declval
- 哈希输出为 BYTE 而不是 std::string