I am getting this error when trying to compile my code.
C:\Users\Quadsam\Desktop\Thing>g++ main.cpp -o main.exe
main.cpp: In function 'int main()':
main.cpp:13:10: error: 'thread' is not a member of 'std'
13 | std::thread threadObj(thread_function);
| ^~~~~~
main.cpp:3:1: note: 'std::thread' is defined in header '<thread>'; did you forget to '#include <thread>'?
2 | #include <thread>
+++ |+#include <thread>
3 |
main.cpp:16:5: error: 'threadObj' was not declared in this scope
16 | threadObj.join();
| ^~~~~~~~~
this is my code main.cpp
#include <iostream>
#include <thread>
void thread_function()
{
for(int i = 0; i < 10000; i++);
std::cout<<"thread function Executing"<<std::endl;
}
int main()
{
std::thread threadObj(thread_function);
for(int i = 0; i < 10000; i++);
std::cout<<"Display From MainThread"<<std::endl;
threadObj.join();
std::cout<<"Exit of Main function"<<std::endl;
return 0;
}
When I installed MinGW I selected to install threads but still get this error.