2013-04-10 85 views
1

我线程程序是:错误编译线程程序

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

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

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

,但它显示的代码块以下错误:

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

我怎样才能解决这个问题我使用Windows和代码块12.11

+0

http://stackoverflow.com/questions/8513980/how-to-compile-the-code-using-include-thread – 2013-04-10 14:31:20

回答

6

首先,你在Windows或Linux?

如果你在linux上,你必须用C++ 11支持编译。只需将-std = C++ 11传递给g ++即可。 我无法帮助你与Windows。

+0

是的,所有缺少的是编译器知道你想建立的标志C++ 11。请参阅[本答案](http://stackoverflow.com/a/6528620/21475)了解如何在Code :: Blocks中对其进行配置。 – Cameron 2013-04-10 14:33:30