lundi 6 juillet 2020

Visual Studio Code c++11 extension warning and lamda warnings

I keep on getting c++11 warnings for no reason. Whenever I use auto it tells me:

 warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]

Also when ever I use lambdas it claims: error: expected expression

When ever I use emplace_back it also claims:

error: no member named 'emplace_back' in 'std::__1::vector<std::__1::pair<int, int>,
      std::__1::allocator<std::__1::pair<int, int> > >'

I've spent too many hours trying to figure how to fix this. I've tried following instructions that people have claimed in: Visual Studio Code c++11 extension warning but it still doesn't work for me. Could anyone tell me where I can find `"clang.cxxflags" because I can't find it in my users settings. I use VS code(terminal) and use a mac.

Here is my JSON:

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "macFrameworkPath": [
                "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
            ],
            "compilerPath": "/usr/bin/clang",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "clang-x64"
            
            
        }
    ],
    "version": 4
}

in "cppStandard", if I change it to c++11 it still displays the same errors, and here is the program:

#include <bits/stdc++.h>
using namespace std;
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    vector<pair<int, int>> inversions;
    for (int i = 0; i < n; i++)
        for (int j = i + 1; j < n; j++)
            if (a[j] < a[i])
                inversions.emplace_back(i, j);
    sort(inversions.begin(), inversions.end(), [&] (pair<int, int> l, pair<int, int> r) {
        if (l.second != r.second)
            return l.second > r.second;
        return l.first < r.first;
    });
    cout << inversions.size() << '\n';
    for (auto p : inversions) {
        cout << p.first + 1 << ' ' << p.second + 1 << '\n';
    }
}

Here are the specific error messages:

tempCodeRunnerFile.cpp:16:16: error: no member named 'emplace_back' in 'std::__1::vector<std::__1::pair<int, int>,
      std::__1::allocator<std::__1::pair<int, int> > >'
                                inversions.emplace_back(i, j);
                                ~~~~~~~~~~ ^
tempCodeRunnerFile.cpp:17:45: error: expected expression
        sort(inversions.begin(), inversions.end(), [&] (pair<int, int> l, pair<int, int> r) {
                                                   ^
tempCodeRunnerFile.cpp:23:7: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
        for (auto p : inversions) {
             ^
tempCodeRunnerFile.cpp:23:14: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
        for (auto p : inversions) {

Thank you

Aucun commentaire:

Enregistrer un commentaire