STL Vector for c++

Thread Starter

coolroose

Joined Aug 31, 2010
16

Please look take a look at my code and tell me if I answer the question right for the assignment in the comment line below. Then help me make it look better please.

Rich (BB code):
/* Use a foward iterator for an STL vector on ints. Populate the vector with 10 ints&display the content of the vector.
Next zero the vector entries&display the vector again.*/
Rich (BB code):
Rich (BB code):
Rich (BB code):
Rich (BB code):
Rich (BB code):
Rich (BB code):
Rich (BB code):
Rich (BB code):
Rich (BB code):
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main (void)
{
vector<int> myvector (10,0 ); // myvector: 0 0 0 0 0 0 0 0
fill (myvector.begin(),myvector.begin()+4,5); // myvector: 5 5 5 5 0 0 0 0
fill (myvector.begin()+3,myvector.end()-2,8); // myvector: 5 5 5 8 8 8 0 0
cout << "The vector contains:";
for (vector<int>::iterator it=myvector.begin(); it!=myvector.end(); ++it)
cout << " " << *it;
cout << endl;
system("pause");

return 0;
}
 
 
Last edited by a moderator:
Top