在代码块中编译线程程序时出错

Error compiling thread program in codeblocks

本文关键字:程序 出错 线程 编译 代码      更新时间:2023-10-16

我的线程程序是:

#include<iostream>
#include<thread>
using namespace std;
void t()
{
    cout<<"from threadn";
}
int main()
{
     thread i(&t);
     cout <<"from mainn";
     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

首先,您使用的是windows还是linux?

如果你在linux上,你必须编译c++ 11支持。只需将-std=c++11传递给c++。我帮不了你的忙。

您的IDE可能还不支持c++ 11。因为thread从c++ 11开始就包含在标准中了。看到这个线程的代码块?http://forums.codeblocks.org/index.php?topic=15536.0