vector<string> div;
 div.pushback("a");
 div.pushback("b");
 div.pushback("c");

 for(int i= 0; i < div.size(); i++) {
  cout << "Letters: " << div[i] << endl;
 }
 cin.get();

Output:

Letters: a
Letters: a, b
Letters: a, b, c

I would like the output like this:

Letters: a
Letters: b
Letters: c

Thanks for your help in advance, Regards X

Edited 3 Years Ago by mike_2000_17: Fixed formatting

If you change div.pushback("a"); to div.push[b]_[/b]back("a"); , your code should actually produce the output you want.

Sorry was a quick rough draft I have used push_back instead of pushback but I am getting the below output problem.

vector<string> div;
 div.push_back("a");
 div.push_back("b");
 div.push_back("c");

 for(int i= 0; i < div.size(); i++) {
  cout << "Letters: " << div[i] << endl;
 }
 cin.get();

will output:

Letters: a
Letters: b
Letters: c

really, I not fooling you or anything....

For vectors and valarrays iterators do not provide any advantages (except more cumbersome codes - if you get pay for every LOC, of course).
So this supposedly C-style operator [] is much more natural vector accessor...

I found the problem thanks guys for your input.

Helped me found the problem in my code.

Thanks, Regards X

This question has already been answered. Start a new discussion instead.