multithreading - CodeBlocks c++ - Can't use Thread because the compiler doesn't support it -
firstly wanted create program count time user input time zero, code -
#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 , " << minutesleft << " minutes left." << endl; secondscount=0; } secondscount++; seconds--; sleep(1000); timer(); } } int main() { // introduction , time picking cout << "welcome timer - please set amount of hours , minutes want timer run" << endl; double requestedhours, requestedminutes; cin >> requestedhours; cin >> requestedminutes; double requestedseconds = requestedhours*3600 + requestedminutes*60; seconds = requestedseconds; cout << "timer started"; timer(); }
but wanted add function in user type word or letter pause program, (and after bit of reearching found out threading) - when added #include <thread>
got massage -
"#error file requires compiler , library support \ iso c++ 2011 standard. support experimental, , must \ enabled -std=c++11 or -std=gnu++11 compiler options. #endif"
how fix this?
you seem using g++ in windows assume flavour of mingw came code::blocks.
gnu glibc doesn't support windows threads (its dev team doesn't care windows) have either use mingw pthread build, or use add-on.
firstly should add -std=c++11
build options.
however, error message suggests have installed quite old version of g++ recommend upgrading mingw-w64 (an actively-maintained fork of mingw). see here installation help.
for more info thread support in various versions of mingw see this thread. use mingw-w64 win32 threads , meganz addon in code::blocks successfully.
Comments
Post a Comment