search

Home  >  Q&A  >  body text

c++ - Qt5环境使用auto类型

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;
           ^
迷茫迷茫2807 days ago707

reply all(2)I'll reply

  • 天蓬老师

    天蓬老师2017-04-17 11:16:53

    Add this sentence to your .pro

    CONFIG += c++11
    

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 11:16:53

    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

    reply
    0
  • Cancelreply