如何在Qt Creator中启用C ++ 11? [英] How to enable C++11 in Qt Creator?

查看:239
本文介绍了如何在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;
}

我收到以下错误:



但是,根据这个文章这个版本的Qt Creator支持C ++ 11。那么如何启用它?

解决方案

根据



到您的.pro文件(参见该网页的底部)。 它需要Qt 5。






其他答案,建议



QMAKE_CXXFLAGS + = -std = c ++ 11 (或 QMAKE_CXXFLAGS + = -std = c ++ 0x



也可与 Qt 4.8和gcc / clang配合使用。


The title is pretty self-descriptive. I've downloaded Qt Creator 2.7.0, and I am trying to compile some basic C++11 code:

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

I'm receiving the following error:

range based for loops are not allowed in c++ 98 mode

Yet, according to this article this version of Qt Creator supports C++11. So how do I enable it?

解决方案

According to this site add

CONFIG += c++11

to your .pro file (see at the bottom of that web page). It requires Qt 5.


The other answers, suggesting

QMAKE_CXXFLAGS += -std=c++11 (or QMAKE_CXXFLAGS += -std=c++0x)

also work with Qt 4.8 and gcc / clang.

这篇关于如何在Qt Creator中启用C ++ 11?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆