【发布时间】:2015-06-15 03:49:00
【问题描述】:
首先我想创建一个程序来计算从用户输入时间到零的时间,这就是代码 -
#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"
如何解决这个问题?
【问题讨论】:
-
您的错误信息正在为您提供解决方案...
-
您安装了支持旧版 C++ 的 CodeBlock。要升级,谷歌“codeblocks C++ 11”。例如:StackOverflow: How can I add C++11 support to code::blocks compiler? 或 YouTube: How to add C++11 support to code::blocks compiler
-
@paulsm4 CodeBlocks 不是编译器,如果此消息出现在
libstdc++中,他使用的是 确实 支持 C++11 的gcc版本它们是一起发货的。 -
@o11c:我知道 Codeblocks 是一个IDE(我更喜欢Eclipse/CDT,谢谢)。关键是,他需要在 Google 上获取 特定于 Codeblocks 的更新程序。这可能与更新 Eclipse 或更新 MinGW 的过程不同,也可能没有不同……或者,就此而言,更新命令行 gcc/g++ 工具链。
-
@paulsm4 除了绝对不需要升级。只需更改项目设置。
标签: c++ multithreading codeblocks