What is the easiest way to initialize a std::vector with hardcoded elements?
If your compiler supports C++11, you can simply do: std::vector<int> v = {1, 2, 3, 4}; This is available in GCC as of version 4.4. Unfortunately, VC++ 2010 seems to be lagging behind in this respect. Alternatively, the Boost.Assign library uses non-macro magic to allow the following: #include <boost/assign/list_of.hpp> … std::vector<int> v = boost::assign::list_of(1)(2)(3)(4); Or: … Read more