[英]thread is not a member of std c++
I'm having this problem where i can't use threads because i keep getting the error "'thread' is not a member of 'std'". 我遇到了无法使用线程的问题,因为我不断收到错误“'线程'不是'std''的成员”。
I am using MinGW with c++11 as a compiler flag.. On the little program i made yesterday it worked fine. 我正在将MinGW与c ++ 11一起用作编译器标志。在昨天制作的小程序中,它工作正常。 Basically i want to play a "beep"-song while playing a little guessing game with pseudo random numbers.
基本上,我想在玩带有伪随机数的猜谜游戏时播放“哔哔”歌曲。
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;
it always gives me the same error ||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)) ===|
它总是给我同样的错误
||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)) ===|
||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)) ===|
and i really dont know why anymore 我真的不知道为什么
Edit: pinkpanther() just plays the pinkpanther song i found in "beeps" 编辑:pinkpanther()只播放我在“哔哔”中找到的pinkpanther歌曲
Edit2: i have a couple libs included (windows,thread,ctime and ctdlib) Edit2:我有几个库(Windows,线程,ctime和ctdlib)
What MinGW build did you use? 您使用了什么MinGW版本? If you got one with the Win32 threading model, it doesn't support C++11 threads;
如果您使用Win32线程模型,则它不支持C ++ 11线程。 you should instead grab one with the POSIX threading model (winpthreads-based), but mind you, it's quite buggy.
您应该改用POSIX线程模型(基于Winpthreads)来抢购一个,但是请注意,这是个问题。
The code you present never does #include <thread>
. 您提供的代码永远不会
#include <thread>
。 So how is the compiler supposed to know what a std::thread
is? 那么,编译器应该如何知道
std::thread
是什么呢?
Fix your problem by adding #include <thread>
to the top of your file. 通过在文件顶部添加
#include <thread>
来解决问题。
Also make sure you use a compiler that actually supports C++11 (or later) and std::thread
. 还要确保您使用的编译器实际上支持C ++ 11(或更高版本)和
std::thread
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.