相关疑难解决方法(0)

如何在Qt Creator中启用C++ 11?

标题非常具有自我描述性.我已经下载了Qt Creator 2.7.0,我正在尝试编译一些基本的C++ 11代码:

int my_array[5] = {1, 2, 3, 4, 5};
for(int &x : my_array)
{
  x *= 2;
}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

range based for loops are not allowed in c++ 98 mode
Run Code Online (Sandbox Code Playgroud)

然而,根据这篇文章,这个版本的Qt Creator支持C++ 11.那么我该如何启用呢?

c++ qt c++11

160
推荐指数
4
解决办法
13万
查看次数

MinGW的C++ 11功能

我尝试将emplace()函数用于unordered_map,编译器说没有这样的函数存在.

我说-std=c+11,它说cc1plus.exe: error: unrecognized command line option '-std=c+11'

我可以以某种方式使用mingw的C++ 11功能吗?

c++ windows mingw c++11

12
推荐指数
1
解决办法
3万
查看次数

c ++ 11 #include <thread>给出编译错误

尝试从已编译的源文件创建目标文件时出现编译错误.我正在使用c ++ 11附带的标题.我还使用了c ++模式识别库和其他几个包含.

我所做的就是添加#include <thread>到我的rbm_test.cc源文件中.

我的编译命令:

g ++ -std = c ++ 11 -O3 -DQUIET -fPIC -pthread -ansi -pedantic -DARCH_INTEL -Wall -W -Wchar-subscripts -Wpointer-arith -Wcast-qual -Wwrite-strings -Wconversion -Wno-old-style -cast -Wctor-dtor-privacy -Wnon-virtual-dtor -I ../ src -I ../ .. -DPATREC -D_ UNIX _ -o rbm_test.o -c ../src/rbm_test.cc

我得到的编译错误是:

错误:#error此文件需要ISO C++ 2011标准的编译器和库支持.此支持目前是实验性的,必须使用-std = c ++ 11或-std = gnu ++ 11编译器选项启用.

奇怪的是,当我编译下面的代码示例时

g ++ -std = c ++ 11 -pthread -c main.cpp -o main.o

那我没有错.

这是 main.cpp

#include <iostream>
#include <thread> …
Run Code Online (Sandbox Code Playgroud)

c++ compiler-errors g++ pthreads

2
推荐指数
1
解决办法
2694
查看次数

标签 统计

c++ ×3

c++11 ×2

compiler-errors ×1

g++ ×1

mingw ×1

pthreads ×1

qt ×1

windows ×1