Since the values are different for each snack, there's no easier way to do it. If you want to initialize each member to the same value, you would use a constructor. For example:
In C++11, it is done as follows:
1
2
3
vector<CandyBar> snacks({{"Mocha Munch",2.3,350},
{"Demons Delight",3.3,666},
{"Troll Jelly",6.9,9001}});
It might require enabling a compiler switch (with GCC it is -std=c++0x).
You shouldn't use manual memory allocation (new[] and delete[]), by the way.
I hope your book told you this.
Ok now I am getting confused.
First I was learning from Herbert Schild books, then I found out that his books are ranked #1 in "books you dont want to read". Then I was learning from thenewboston.com and it somehow felt wrong, beacuse he didnt explain alot of stuff etc.
Now my third source for learning seem to be bad too.
I tend to recommend the C++ Primer (without the Plus).
I haven't heard anything bad about the C++ Primer Plus, though (but not anything particularly good either).
You shouldn't use manual memory allocation (new[] and delete[]) if there is a reasonable alternative available, by the way
fixed.
There shouldn't be any books out there that include C++11 yet, as there is no complete implementation of C++11 yet (at least none that I am aware of).
And I think that syntax is already allowed for POD types in C++03 (and earlier too, it's an import from C). C++11 doesn't require the ()'s around the expression btw. (and neither does C++03)
Another option would be just writing a constructor. Doesn't save you the work of providing the values, but does save you the work of assinging each of them manually.
So basically, always (just as there are always exceptions - however, when you are in such an exceptional situation, you'll be aware of it anyway - it doesn't taint the rule).
And I think that syntax is already allowed for POD types in C++03 (and earlier too, it's an import from C).