c++ - Qt5环境使用auto类型
迷茫
迷茫 2017-04-17 11:14:53
0
2
718

auto自动类型推断,用于从初始化表达式中推断出变量的数据类型,我在Qt5下面写的C++代码为什么出错?难道Qt5还不支持C++11?

#include <iostream>
using namespace std;
int main()
{
    auto k=5;
    return 0;
}

错误如下:

C:\Users\Administrator\Desktop\untitled\main.cpp:7: 
错误:'k' does not name a type
     auto k=5;
          ^C:\Users\Administrator\Desktop\untitled\main.cpp:8:
错误:'k' was not declared in this scope
     cout<<k<<endl;
           ^
迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(2)
Peter_Zhu

Add this sentence to your .pro

CONFIG += c++11
刘奇

I don’t know which QT version of which platform the poster is using. Mine is ok. The environment is QT5.1.1 Mac OS Or the compiler is too old, please install the latest C++ compiler

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template