std随机函数不起作用-Qt MinGw [英] std random functions not working - Qt MinGw

查看:160
本文介绍了std随机函数不起作用-Qt MinGw的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用QtCreator 2.4.1,QtSdk 4.8.1和MinGw 4.7.2

I am using QtCreator 2.4.1, with QtSdk 4.8.1 and MinGw 4.7.2

我正在尝试使用(c ++ 11)随机库,但是到目前为止,我一直没有成功.采取以下示例代码:

I am trying to use the (c++11) random library, but so far I have been unsuccesful. Take the following sample code:

#include <random>
...
std::default_random_engine generator;
std::uniform_int_distribution<int> distribution(1,6);
int dice_roll = distribution(generator);  // generates number in the range 1..6

编译器抱怨:

错误:"default_random_engine"不是"std"的成员

error: 'default_random_engine' is not a member of 'std'

错误:"uniform_int_distribution"不是"std"的成员

error: 'uniform_int_distribution' is not a member of 'std'

我的.pro文件中有-std = c ++ 0x标志.所有其他STL功能似乎都能正常运行,所以我很困惑! 如果有人可以帮我这个忙,我将不胜感激.

I've got the -std=c++0x flag in my .pro file. All other STL functionality seems to work properly, so I'm puzzled! I'd be grateful if someone could give me a hand with this.

推荐答案

很好,很愚蠢的问题,但是可能会发生在其他人身上,所以我们去:

Well, silly problem, but might happen to others, so here we go:

由于某种原因,我的代码是用MinGW 4.4编译的,该版本是Qt Creator默认附带的版本.要将其恢复到我已经安装在计算机中的MinGw 4.7.2,我单击了QCreator屏幕左侧的项目"选项卡,然后选择了正确的工具链.

For some reason my code was being compiled with MinGW 4.4, the version that shipped by default with my Qt Creator. To bring it back to MinGw 4.7.2, which I already had installed in my computer, I clicked on the 'Projects' tab on the left of the QCreator screen, then selected the correct tool chain.

感谢荷亚姆·皮尔博格(Joachim Pileborg)向我指出正确的方向.

Thanks loads to Joachim Pileborg for pointing me in the right direction.

这篇关于std随机函数不起作用-Qt MinGw的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆