【发布时间】:2019-01-31 01:45:49
【问题描述】:
我遇到了无法使用线程的问题,因为我不断收到错误消息“'thread' is not a member of 'std'”。
我正在使用带有 c++11 的 MinGW 作为编译器标志。在我昨天制作的小程序上,它运行良好。基本上我想在玩伪随机数的小猜谜游戏时播放“哔”的歌曲。
int rnumber, guess, maxrand;
std::thread t1(pinkpanther);
t1.detach();
cout << "What do you want the maximum Number to be? ";
cin >> maxrand;
rnumber = randy(maxrand);
//Start
cout << endl << "This is a game!" << endl << "You have 5 tries to guess the random number generated by this program, have fun" << endl;
for (int i = 0; i < 5; i = i + 1)
{
cout << "Your guess: ";
cin >> guess;
if (guess < rnumber)
{
cout << "Your guessed number is smaller than the answer! Try again!" << endl << endl;
}
else if (guess > rnumber)
{
cout << "Your guessed number is bigger than the answer! Try again!" << endl << endl;
}
else
{
cout << "you guessed the right number!";
break;
}
}
return 0;
它总是给我同样的错误
||In function 'int main()':|
'thread' is not a member of 'std'|
't1' was not declared in this scope|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
我真的不知道为什么了
编辑:pinkpanther() 只播放我在“哔”中找到的粉红豹歌曲
Edit2:我有几个库(windows、thread、ctime 和 ctdlib)
【问题讨论】:
-
你
#include <thread>了吗? -
似乎前几行在复制和粘贴过程中丢失了。有些行不太相关,但很可能第一行(或缺少某些东西的事实)很重要
-
是的,我有,我会编辑让你看到我
-
另外请阅读minimal reproducible example。如果您的代码不包含与问题无关的内容,我们更容易为您提供帮助。例如,我敢打赌,如果你删除了整个循环,你的代码会产生同样的错误
-
MinGW 以不支持
std::thread而闻名。 MinGW-w64 是一个替代方案。
标签: c++ multithreading random std