[Solved] How to get each iteration in a for loop into a list/vector? (C++)


First of all, this: var array = [], and the rest of your code, is not c++ syntax at all, it’s pure javascript. You can’t copy code from one language to another expecting that would compile and run properly.

In order to insert all elemnts from N to 0 and then N again to a vector you need to :

  1. include the vector library : #include <vector>
  2. initiate an N value (from a user, using cin in by including iostream for example OR manually, i.e. N = 6)
  3. Read through the following code to see how to enter all numbers wanted numbers to a vector here (use push_back). Note: Also, as @NathanOliver mentioned, you can use reverse if you know N in advanced. look here for simple reference.
  4. And then, push also N in the end manually (vec.push_back(N))

And I’m really saying that for you, try to work this out yourself before someone here gives you the complete code.

2

solved How to get each iteration in a for loop into a list/vector? (C++)