Errors in clion that work within Udacity

已完成

Morning I am facing an issue and also learning c++ at the same time. While going through the course in Udacity this code works in the notebook but not in clion:

#include <iostream>
#include <vector>
using std::vector;
using std::cout;

int main() {
    vector<int> a = {0, 1, 2, 3, 4};
    // Add some code here to access and print elements of a.
    cout << a[0];
    cout << a[1];
    cout << a[2];
    cout << a[3];
    cout << a[4];
    
    cout << "\n";
}

instead it gives me this error:

error: non-aggregate type 'vector<int>' cannot be initialized with an initializer list
    vector<int> a = {0, 1, 2, 3, 4};
                ^   ~~~~~~~~~~~~~~~
1 error generated.

Thanks for your time.

0

I solved this issue.

The project was missing the cmake file.

0

请先登录再写评论。