0
首先,我想創建一個程序,將計算時間從用戶輸入時間到零,這是代碼 -代碼塊C++ - 無法使用線程,因爲編譯器不支持它
#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();
}
但是,比我想添加一個功能,其中用戶可以鍵入一個字或一個字母來暫停程序,(和一些reearching後,我發現了線程) - 但是當我加入#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++的CodeBlocks。要升級,Google會「阻止C++ 11」。例如:[StackOverflow:如何將C++ 11支持添加到代碼::塊編譯器?](http://stackoverflow.com/questions/18174988/how-can-i-add-c11-support-to- codeblocks編譯器)或[YouTube:如何將C++ 11支持添加到code :: blocks編譯器](https://www.youtube.com/watch?v=SNLZEhWZ1og) – paulsm4
@ paulsm4 CodeBlocks不是編譯器,並且如果這個消息出現在'libstdC++'中,他正在使用'gcc'版本,* *支持C++ 11,因爲它們一起發貨。 – o11c