I would expect this to ouput the 5 doubles, but instead I get the output below.

vector<double> a(5);
	a.push_back(1.2);
	a.push_back(1.3);
	a.push_back(1.4);
	a.push_back(1.5);
	a.push_back(1.6);

    vector<double>::iterator i;
 
    i = a.begin();

    while( i != a.end() )
	{
		cout << *i << endl;
		i++;
	}
0
0
0
0
0
1.2
1.3
1.4
1.5
1.6

Any ideas why?

Thanks,

Dave

>>vector<double> a(5);
That creates an array of 5 doubles.

>> a.push_back(1.2);
That adds an additional element to the array, so after this line executes the array will have 6 elements.

oh hahahahaha geez I thought it was something to do with the iterator.. but it's just PEBCAK (isn't that the acronym? problem exists between chair and keyboard?) haha

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.