0
\$\begingroup\$

Noob here,

I am trying to display a list of a vector with ascending numbers. To display the list I iterate through the following code.

cout << "\nYour games list is: \n"; for (iter = gameTitle.begin(); iter != gameTitle.end(); ++iter) { cout << listNum << ".- " << *iter << endl; }

So listNum is an integer that I initialized as "0" but this particular setup will give me a list with three elements as follows.
3.- userInput
3.- userInput
3.- userInput

"userInput" is a vector of string type that is declared yet not initialized.

¿How do I get a list like follows?
1.- userInput
2.- userInput
3.- userInput
etc.

Thanks

\$\endgroup\$
1
  • 3
    \$\begingroup\$ This is a basic programming question (not game-specific) so probably belongs elsewhere, maybe stack overflow. In your code, please show everything to do with listNum. Your question hinges on what listNum does, but you're not showing that part! (Probably you just need listNum = 0; before the for(), and listNum++ inside it.) \$\endgroup\$ Commented Mar 28, 2015 at 21:00

1 Answer 1

0
\$\begingroup\$

You could either: post increment listNum prior to outputting listNum, assign your iter to listNum prior to outputting listNum, or instead of outputting listNum, just replace it with iter.

The issue at hand is that your are not incrementing listNum.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged .