I'm going to keep it fast and simple.
Here's the code I've written:
#include <iostream>
#include <thread>
void myFunc()
{
std::cout << "Hello!" << std::endl;
}
int main()
{
std::thread myThread(myFunc);
myThread.join();
return 0;
}
This is the command I've used to compile the program:
g++ threads.cc -o threads.exe -std=c++11
This is the error I'm getting:
threads.cc: In function 'int main()':
threads.cc:11:6: error: 'thread' is not a member of 'std'
std::thread myThread(myFunc);
^
threads.cc:13:6: error: 'myThread' was not declared in this scope
myThread.join();
^
I'm running Windows 10 and as you can see I'm trying to compile the program with GCC.
Can anyone help me with this? I've tried a few different ways to do multi-threading in C++, but none have worked.
The day after tomorrow I'll attend to a programming competition at my school and to make things go faster (the programs may only take up to 5 seconds to process data, which can be a lot) I'm thinking multi-threading could really help. You might think I should know this if I learn programming at school, but I haven't started that course yet and I'm just interested in the competition because it seems fun.
Aucun commentaire:
Enregistrer un commentaire