The C ++ 98 standard does not support initializer lists for initializing standard containers.
Try setting the appropriate compiler options to compile the code in accordance with the C ++ 2011 standard.
Another approach is to add elements to the vector individually, for example
std::vector<int> v1; v1.reserve( 3 ); v1.push_back( 4 ); v1.push_back( 3 ); v1.push_back( 5 );
Instead of the push_back
member function, you can use the overloaded +=
operator. for instance
std::vector<int> v1; v1.reserve( 3 ); v1 += 4; v1 += 3; v1 += 5;
Or use an array of type
const size_t N = 3; int a[N] = { 4, 3, 5 }; std::vector<int> v1( a, a + N );
source share