I am trying to learn C++, and I cant seem to get threading to work.
#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;
}
identifier "thread" is undefined
Im on C++14
minGW info:
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/8.2.0/lto-wrapper.exe
Target: mingw32
Configured with: ../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-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-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-format-warnings
Thread model: win32
gcc version 8.2.0 (MinGW.org GCC-8.2.0-3)
this is what happends if I compile via 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);
^~~~~~
main(){
should beint main(){
2) Are you compiling with C++-11 enabled? – Algirdas Preidžiusthread
– NathanOliver