我正在尝试学习C ++,但似乎无法使线程正常工作。
#include <iostream>
#include <thread>
using namespace std;
void thing(){
cout << "1 is a thing" << endl;
int num;
cin >> num;
}
int main(){
cout << "is 1 a thing?" << endl;
thread neat1(thing);
return 0;
}
标识符“线程”未定义
我在C ++ 14上
minGW信息:
使用内置规格。
COLLECT_GCC = g ++
COLLECT_LTO_WRAPPER = c:/ mingw / bin /../ libexec / gcc / mingw32 / 8.2.0 / lto-wrapper.exe
目标:mingw32
配置为:../src/gcc-8.2.0/configure --build = x86_64-pc-linux-gnu --host = mingw32 --target = mingw32 --prefix = / mingw --disable-win32-registry- -with-arch = i586 --with-tune =通用--enable-languages = c,c ++,objc,obj- c ++,fortran,ada --with-pkgversion ='MinGW.org GCC-8.2.0-3' --with-gmp = / mingw --with-mpfr = / mingw --with-mpc = / mingw --enable-static --enable-shared --enable-threads --with-dwarf2 --disable-sjlj-例外-启用版本特定的运行时库--with-libiconv-prefix = / mingw --with-libintl- prefix = / mingw --enable-libstdcxx-debug --with-isl = / mingw --enable -libgomp --disable-libvtv --enable-nls --disable-build-format-warnings
线程模型:win32
gcc版本8.2.0(MinGW.org GCC-8.2.0-3)
如果我通过cmd进行编译,就会发生这种情况
>g++ first.cpp -std=c++11
first.cpp: In function 'int main()':
first.cpp:13:5: error: 'thread' was not declared in this scope
thread neat1(thing);
^~~~~~
first.cpp:13:5: note: 'std::thread' is defined in header '<thread>'; did you forget to '#include <thread>'?
first.cpp:3:1:
+#include <thread>
using namespace std;
first.cpp:13:5:
thread neat1(thing);
^~~~~~
答案 0 :(得分:0)
我的编译器原来是问题所在,因此我从在线安装程序的https://sourceforge.net/projects/mingw-w64/files/中删除了旧的编译器,并获得了新的MinGW编译器。设置完成后,线程工作正常。