0

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

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by daviddoria
0

>>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.

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.