auto 关键字在 Dev C++ 中不起作用
auto keyword not working in Dev c++
这是我为查看 auto
关键字如何工作而编写的代码,但它没有在 Dev C++ 中编译并给出以下警告:
[警告] C++11 自动仅适用于 -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)?
这是我为查看 auto
关键字如何工作而编写的代码,但它没有在 Dev C++ 中编译并给出以下警告:
[警告] C++11 自动仅适用于 -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)?