1

My thread program is:

#include<iostream>
#include<thread>
using namespace std;

void t()
{
    cout<<"from thread\n";
}

int main()
{
     thread i(&t);
     cout <<"from main\n";
     i.join();
}

but it shows following error in codeblocks:

1)'thread ' was not declared in this scope
2)expected ';' before 'i'
3)'i' was not declared in this scope 

How can I solve it?I am using windows and codeblocks 12.11

2 Answers2

6

First, are you on windows or linux?

If you are on linux, you must compile with C++11 support. Just pass -std=c++11 to g++. I can't help you with windows.

Minas Mina
  • 2,058
  • 3
  • 21
  • 35
  • Yep, all that's missing is a flag for the compiler to know you want to build under C++11. See [this answer](http://stackoverflow.com/a/6528620/21475) for how to configure that in Code::Blocks. – Cameron Apr 10 '13 at 14:33
0

Your IDE may not support C++11 yet. since thread is included in the standard since C++11. See this thread for CodeBlocks? http://forums.codeblocks.org/index.php?topic=15536.0

taocp
  • 23,276
  • 10
  • 49
  • 62