Create a fixed size std::vector and write to the elements
问题 In C++ I wish to allocate a fixed-size (but size determined at runtime) std::vector then write to the elements in this vector. This is the code I am using: int b = 30; const std::vector<int> test(b); int &a = test[3]; However, this gives me a compiler (MSVC 2010 Pro) error: error C2440: 'initializing' : cannot convert from 'const int' to 'int &'. Conversion loses qualifiers. My understanding of const is that it makes all of the member variables of a class constant. For example, the following