CodeBlocks 无法使用 Thread,因为编译器不支持它
CodeBlocks Can't use Thread because the compiler doesn't support it
首先,我想创建一个程序,将用户输入时间的时间计算为零,这就是代码 -
#include <iostream>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <dos.h>
#include <windows.h>
#include <thread>
using namespace std;
// sleep(5000);
int runTimer = 1;
int seconds;
int hoursLeft;
int minutesLeft;
int secondsCount=0;
void timeLeft ()
{
hoursLeft = seconds/3600;
minutesLeft = seconds/60 - hoursLeft*60;
}
void timer ()
{
while(runTimer=1)
{
if (secondsCount == 60)
{
timeLeft();
cout << "The Amount of time left is: " << hoursLeft << " hours and " << minutesLeft << " minutes left." << endl;
secondsCount=0;
}
secondsCount++;
seconds--;
Sleep(1000);
timer();
}
}
int main()
{
// introduction and time picking
cout << "Welcome to my Timer - Please set the amount of hours and than minutes you want the timer to run" << endl;
double requestedHours, requestedMinutes;
cin >> requestedHours;
cin >> requestedMinutes;
double requestedSeconds = requestedHours*3600 + requestedMinutes*60;
seconds = requestedSeconds;
cout << "Timer Started";
timer();
}
但是我想添加一个功能,用户可以在其中键入一个单词或字母来暂停程序,(经过一番整理后,我发现了线程) - 但是当我添加#include <thread>
时,我得到了这个按摩 -
"#error This file requires compiler and library support for the
ISO C++ 2011 standard. This support is currently experimental, and must be
enabled with the -std=c++11 or -std=gnu++11 compiler options.
#endif"
如何解决这个问题?
你似乎在Windows中使用g++,所以我认为它是Code::Blocks附带的MinGW的一个风格。
GNU glibc不支持Windows线程(它的开发团队不关心Windows),所以你必须使用MinGW pthread构建,或者使用附加组件。
首先,您应该将-std=c++11
添加到构建选项中。
但是,您的错误消息表明您已经安装了相当旧版本的g ++,因此我建议升级到Mingw-w64(Mingw的积极维护分支)。有关安装帮助,请参阅此处。
有关各种版本的 MinGW 中的线程支持的更多信息,请参阅此线程。我成功地将 Mingw-w64 与 Win32 线程和 Code::Blocks 中的 meganz 插件一起使用。
相关文章:
- C/C++编译器通常会删除重复的库吗
- 模板-模板参数推导:三个不同的编译器三种不同的行为
- Win32编译器选项和内存分配
- C++ Windows 驱动程序MSB3030无法复制该文件,因为它找不到
- MSVC多行宏编译器错误
- 静态数据成员的问题-修复链接错误会导致编译器错误
- C++,我收到一个无法理解的编译器错误
- 在线编译器中的分段C++没有打印消息
- 如何解决gcc编译器优化导致的centos双编译器设置中的分段错误
- C/C++预处理器是否可以检测一些编译器选项
- 是否有C++编译器选项允许激进地删除所有函数调用,并将参数传递给具有空体的函数
- C++错误C2600:无法定义编译器生成的特殊成员函数(必须首先在类中声明)
- 我需要知道编译器如何在cpp中使用析构函数
- 编译器如何区分std::vector的构造函数
- CLANG 编译器 说:变量"PTR"可能未初始化
- 说编译器可以将下面的表达式"a->i"替换为其值 1 是否正确,因为...?
- 编译器错误,因为构造函数必须显式初始化成员
- c++应用程序找不到com dll,因为编译器使用不正确的guid生成.tlh文件
- 不能将一个指针赋值给另一个指针,因为类型不匹配,或者编译器是这么说的
- CodeBlocks 无法使用 Thread,因为编译器不支持它