piero borrelli piero borrelli - 10 days ago 6
C++ Question

Error with the creating of my first vector [Visual studio 2013]

I'm studying the C++ programming language and I'm having some problem with my first vector. If i follow the example in the book (programming principles and practice using C++), this is the example :

vector<int> v = { 5, 7, 9, 4, 6, 8 };


and here what my compiler says : Errore 1 error C2440: 'initializing' : cannot convert from 'initializer-list' to 'Vector' c:\users\pierob\documents\visual studio 2013\projects\learnprogramming\learnprogramming\main.cpp 7 1 learnprogramming

can you help me please ? I have visual studio 2013 express (I use the visual C++ compiler november 2013 ctp).

Answer

The error message states Vector, not vector, so something looks suspicious as to the code you're actually compiling.

Using Visual Studio 2013 Update 3, the following compiles with 0 errors:

#include <vector>

int main()
{
    std::vector<int> v = { 5, 7, 9, 4, 6, 8 };
}

Output:

1>  main.cpp
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

Please copy the above code and compile it to ensure it gives no errors.