我正在尝试学习 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 上未定义 Im
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=generic --enable-语言=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-exceptions --enable-version-specific-runtime-libs --with-libiconv -prefix=/mingw --with-libintl- prefix=/mingw --enable-libstdcxx-debug --with-isl=/mingw --enable-libgomp --disable-libvtv --enable-nls --disable-build -格式警告
线程模型: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);
^~~~~~