0

I just set up visual studio code and made a very basic c++ program to test it:

#include <iostream>
#include <vector>

using namespace std;

int main() {
    vector<int> vec = {1, 2, 3, 4, 5};
    for (const auto &i : vec) {
        cout << i << endl;
    }
}

I'm not sure if I did anything wrong, but I get the following errors:

test.cpp:7:17: error: non-aggregate type 'vector<int>' cannot be initialized with an initializer list
    vector<int> vec = {1, 2, 3, 4, 5};
                ^     ~~~~~~~~~~~~~~~
test.cpp:8:16: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
    for (const auto &i : vec) {
               ^
test.cpp:8:24: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
    for (const auto &i : vec) {
                       ^
2 warnings and 1 error generated.

In cpp standard, it says its using c++20. I'm not sure what compiler I'm using, because in settings it looks like it is using clang, but when it runs, the description says:

cd "/Users/(my name)/Dropbox/Mac/vsCodeProjects/c:c++/" && g++ test.cpp -o test && "/Users/(my name)/Dropbox/Mac/vsCodeProjects/c:c++/"test

Because it says g++ there I'm not sure if it using clang after all, but I can't check the version of g++ because when I do it returns the clang version. I've tried everything I've seen and fiddled a lot with the tasks.json and the cpp standard json but nothing works. Any help is appreciated.

0 Answers0