【发布时间】:2013-11-22 17:11:51
【问题描述】:
我创建了一个简单的程序来学习如何使用线程。这是我创建的代码
#include <iostream>
#include <stdlib.h>
#include <thread>
using namespace std;
void count_asc();
void count_desc();
int main() {
thread first(count_asc);
thread second(count_desc);
first.join();
second.join();
system("pause");
return 0;
}
void count_asc(){
int ctr;
for(ctr=1;ctr<=10;ctr++){
cout<<"First thread: "<<ctr<<endl;
}
}
void count_desc(){
int ctr;
for(ctr=10;ctr>=1;ctr--){
cout<<"Second thread: "<<ctr<<endl;
}
}
我正在使用 Dev C++ 5.5.3。我已经阅读了有关此的其他问题,但我作为编程初学者并不能真正理解高级指令。编译此代码时会产生以下错误
main.cpp: In function 'int main()':
main.cpp:11:2: error: 'thread' was not declared in this scope
main.cpp:11:9: error: expected ';' before 'first'
main.cpp:12:9: error: expected ';' before 'second'
main.cpp:14:2: error: 'first' was not declared in this scope
main.cpp:15:2: error: 'second' was not declared in this scope
我已经在 c++ 编译器中包含了 -std=c++11 在 Dev C++ 的项目选项中的附加命令行选项,但我仍然无法删除错误。你能检查一下我做错了什么吗?我也尽可能不想开始使用其他库,因为我很难构建它们(例如 boost)
【问题讨论】:
-
Dev C++ 使用哪个编译器(包括版本)?
-
我认为这是一个 TDM-GCC 4.7.1 32/64bit
-
我已经用
Windows标记了你的问题,正如你所说的编译器所暗示的那样。
标签: c++ windows gcc c++11 dev-c++