问题描述
我正在尝试使用 MinGW g++(i686-win32-dwarf-rev0,由 MinGW-W64 项目构建)8.1.0 编译此代码
#include <bits/stdc++.h>
using namespace std;
int main()
{
map<int,int> mmap;
mmap[0]=10;
mmap[1]=20;
mmap[2]=30;
mmap[3]=40;
mmap[4]=50;
for(auto [x,y]:mmap){
cout<<x<<"->"<<y<<endl;
}
return 0;
}
使用 c++11 标志编译给出了这个
E:\Code>g++ temp.cpp -std=c++11
temp.cpp: In function 'int main()':
temp.cpp:89:14: warning: structured bindings only available with -std=c++17 or -std=gnu++17
for(auto [x,y]:mmap){
并使用 c++17 标志进行编译会出现错误行。
g++ temp.cpp -std=c++17
解决方法
好的,所以我想通了,这是第一行
#include <bits/stdc++.h>
包含 iostream 和 map 而不是上面的行会导致编译干净。
#include<iostream>
#include<map>