【问题标题】:g++ -std=c++17 gives lines and lines of errorsg++ -std=c++17 给出一行一行的错误
【发布时间】:2021-07-29 10:16:12
【问题描述】:

我正在尝试使用 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

【问题讨论】:

  • 这能回答你的问题吗? Why should I not #include <bits/stdc++.h>?
  • 它支持这个想法。因为没有暗示表明问题出在该特定行上。 cmd 只是因为错误而疯狂,而不是暗示它在包含 bits/stdc++.h 时存在问题。

标签: c++ c++11 g++ maps c++17


【解决方案1】:

好的,所以我想出来了,这是第一行

#include <bits/stdc++.h>

包含 iostream 和 map 而不是上面的行会导致编译干净。

#include<iostream>
#include<map>

现在我对Why should I not #include <bits/stdc++.h>?还有一个理由

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-11
    • 2022-06-12
    • 2021-10-26
    相关资源
    最近更新 更多