Correct way to work with vector of arrays

You cannot store arrays in a vector or any other container. The type of the elements to be stored in a container (called the container’s value type) must be both copy constructible and assignable. Arrays are neither. You can, however, use an array class template, like the one provided by Boost, TR1, and C++0x: (You’ll … Read more

How to shuffle a std::vector?

From C++11 onwards, you should prefer: Live example on Coliru Make sure to reuse the same instance of rng throughout multiple calls to std::shuffle if you intend to generate different permutations every time! Moreover, if you want your program to create different sequences of shuffles each time it is run, you can seed the constructor of the random engine … Read more

How do I print out the contents of a vector?

If you have a C++11 compiler, I would suggest using a range-based for-loop (see below); or else use an iterator. But you have several options, all of which I will explain in what follows. range-based for-loop (C++11) In C++11 (and later) you can use the new range-based for-loop, which looks like this: The type char … Read more