我做了功课,并在网上搜索了一个答案。以下简单的代码不编译:minGW(带g ++ 4.7.1)不编译简单的C++ 11代码(在WinVista下)
#include <thread>
#include <iostream>
void hello()
{
std::cout << "Hello from thread " << std::endl;
}
int main()
{
std::thread t1(hello);
t1.join();
return 0;
}
这是非常简单的代码,但我发现了以下错误:
Thread_Cpp11_002.cpp: In function 'int main()'
Thread_Cpp11_002.cpp:14:5: error: 'thread' is not a member of 'std'
Thread_Cpp11_002.cpp:14:17: error: expected ';' before 't1'
Thread_Cpp11_002.cpp:15:5: error: 't1' was not declared in this scope
而且我已经尝试了很多事情,没有一个是有工作:
- 使用
thread
声明t1
代替std::thread
- 使用g ++ 4.8编译。 0
- 使用下面的标志,单独和集体:
-pthread
,-std=gnu++11
,-std=c++0x
,-std=c++11...
所以,我认为这个问题值得被张贴在这里。
这些编译是通过命令行完成的。我有它的工作后,我会尝试使用Code :: Blocks 12.11,它适用于C++ 98。
请记住,我正在使用Windows Vista。
没有关于缺少'#include'的错误? – zneak 2013-04-26 02:07:29
你传递给编译器的参数是什么?它应该有-std = C++ 11。 – Elazar 2013-04-26 02:08:32
@zneak,我也试图改变使用“thread.h”或,在这两种情况下编译neiher发起(没有这样的文件)。 –
ajmacedo
2013-04-26 02:28:25