c++ - auto 关键字在 Dev C++ 中不起作用

标签 c++ vector compiler-errors dev-c++ auto

<分区>

这是我编写的代码,用于查看 auto 关键字如何工作,但它没有在 Dev C++ 中编译并给出以下警告: [警告] C++11 auto 仅适用于 -std=c++11 或 -std=gnu++11 如何克服这个故障并按照警告的指示去做?

#include<iostream>
#include<string>
#include<vector>

using namespace std;
int main()
{
    std::vector<auto> v={2,-1,4,6,7};
    auto beg = v.begin();
    while (beg != v.end())
    {
        ++beg;
        cout<<beg;
    }
}

最佳答案

您需要使用开关指令在编译器中启用 c++11,可在此处找到:How to change mode from c++98 mode in Dev-C++ to a mode that supports C++0x (range based for)?

关于c++ - auto 关键字在 Dev C++ 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45387292/

相关文章:

c++ - 通过引用传递一个 mat 对象 OpenCv

c++ - 使用 cv::FlannBasedMatcher 和 std::vector 的堆损坏

c++ - 为什么 vector<int * const> 是非法的/不合逻辑的?

C++ 编译器错误 C2679 : binary '=' : no operator found

compiler-errors - 用于MPLAB的示例USB项目上的编译错误

c++ - std::move a const std::vector in a lambda capture

c++ - 什么是 std::map<K,V>::map;以及如何知道在实现/使用 STL 容器和函数时使用什么命名空间?

c++ - 按升序合并两个数组(两个数组大小相同)

c++ - 为什么复制构造函数被调用了 25 次,而插入循环只迭代了 10 次?

c++ - Visual Studio 2013 编译成功但有明显错误