我一直有一个错误声明线程类对象。我尝试了这个代码,它给了我错误' '线程'没有在这个范围内声明' '。如果它有帮助,我正在使用MinGW GCC编译到Windows。
#include <iostream>
#include <thread>
using namespace std;
void func(){
cout << "Hello from thread 2n";
}
int main(){
cout << "Hello from thread 1n";
thread t2(func);
t2.join();
return 0;
}
编译给了我"error: 'thread' was not declared in this scope
">
在mingw中没有线程,但是您可以使用像这样的库mingw-std- Threads。