With an array you can do this:
int a[] = { 1,2,3,4,5,6 }
How do you do this with a vector?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could write this, though its not an initialization, but looks very appealing:
And to support this syntax, you need two utility operators defined as:
And you’re done!
Test code:
Output:
Online demo : http://www.ideone.com/1hyR3
Using the utility operators, you actually can avoid temporary variables such as the one in @Als’s solution, and you can write this without boost!