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

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

Member Avatar for iamthwee

This isn't a problem with vector.

Your code is wrong. Post the whole program.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.