Yes in C ++ 11 you can do
std :: vector v {1,2,3,4};
you can create multiple elements of the same value via constructor in C ++ 98
std::vector<int> v (5, 6);
if you don't have C ++ 11, you can create some kind of push back object
#include <vector> struct pb{ std::vector<int>& v_; pb(std::vector<int>& v) : v_(v){}; pb& operator+(int i) { v_.push_back(i); return *this; } }; int main() { std::vector<int> d; pb(d)+4+3; }
source share