I am using g++ --version "g++.exe (MinGW.org GCC-6.3.0-1) 6.3.0" While running this program getting 'thread' was not declared in this scope error even after included thread header file.
.\DemoThread.cpp:17:5: error: 'thread' was not declared in this scope thread testThread(funThread, 5); ^~~~~~ .\DemoThread.cpp:19:5: error: 'testThread' was not declared in this scope testThread.join();
Code :
#include<iostream>
#include<thread>
using namespace std;
void funThread(int num) {
for(int i =0; i< num; i++) {
cout<< "I am in thread" << endl;
}
}
int main() {
thread testThread(funThread, 5);
testThread.join();
return 0;
}
Compiling using below command : g++ -Wall -g -std=c++11 .\DemoThread.cpp -o Demothread