Version:5.4.2
OS version:windows 7
Error reported:
14 5 C:\Users\Adam\Documents\test coding\flush test.cpp [Error] 'thread' was not declared in this scope
Stack trace:
C:\Users\Adam\Documents\test coding\flush test.cpp In function 'void f()':
7 5 C:\Users\Adam\Documents\test coding\flush test.cpp [Error] 'this_thread' has not been declared
C:\Users\Adam\Documents\test coding\flush test.cpp In function 'int main()':
14 5 C:\Users\Adam\Documents\test coding\flush test.cpp [Error] 'thread' was not declared in this scope
14 12 C:\Users\Adam\Documents\test coding\flush test.cpp [Error] expected ';' before 't1'
15 5 C:\Users\Adam\Documents\test coding\flush test.cpp [Error] 'this_thread' has not been declared
16 5 C:\Users\Adam\Documents\test coding\flush test.cpp [Error] 'clog' was not declared in this scope
16 5 C:\Users\Adam\Documents\test coding\flush test.cpp [Note] suggested alternative:
1 0 C:\Users\Adam\Documents\test coding\flush test.cpp In file included from C:\Users\Adam\Documents\test coding\flush test.cpp
64 18 c:\program files (x86)\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.7.1\include\c++\iostream [Note] 'std::clog'
17 5 C:\Users\Adam\Documents\test coding\flush test.cpp [Error] 't1' was not declared in this scope
Steps needed to reproduce the problem:
I am trying to use the <thread> include, and it doesn't seem to be recognized. From what my research has told me it is a standard C++11 header file, but I have used both GNU C++11 and ISO C++11 and neither of them have been able to include it.
code:
#include <iostream>
#include <chrono>
#include <thread>
void f()
{
std::cout << "Output from thread...";
this_thread::sleep_for(std::chrono::seconds(2));
std::cout << "...thread calls flush()\n";
std::cout.flush();
}
int main()
{
thread t1(f);
this_thread::sleep_for(std::chrono::seconds(1));
clog << "Output from main\n";
t1.join();
}
Hello,
Firstly, You forgot to add std:: eg. std::thread t1(f); std::clog << "Output from main\n";
Secondly, version of MinGW bundled with Dev-C++ doesn't support C++11 threads at all, here is partial solution of your problem: http://tehsausage.com/mingw-std-thread-gcc-4-7
Works with Piotr's fixes using TDM-GCC 4.8.1 which you can download from the Compilers section in the download section:
Output from thread...Output from main
...thread calls flush()
Process exited with return value 0
Press any key to continue . . .