gpt4 book ai didi

c++ - thread 不是 std c++ 的成员

转载 作者:行者123 更新时间:2023-11-28 04:34:09 30 4
gpt4 key购买 nike

我遇到了无法使用线程的问题,因为我一直收到错误“'thread' is not 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;

它总是给我同样的错误
||在函数“int main()”中:|
“thread”不是“std”的成员|
't1' 未在此范围内声明|
||=== 构建失败:2 个错误,0 个警告(0 分钟,0 秒)===|
我真的不知道为什么了

编辑:pinkpanther() 只是播放我在“哔哔声”中找到的 pinkpanther 歌曲

Edit2:我有几个库(windows、thread、ctime 和 ctdlib)

最佳答案

您使用的是什么 MinGW 版本?如果你有一个 Win32 线程模型,它不支持 C++11 线程;您应该改用 POSIX 线程模型(基于 winpthreads),但请注意,它有很多问题。

关于c++ - thread 不是 std c++ 的成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52006812/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com