how to create a vector of a class object ?

i need to create a vector of a class object, for example n copies of an object a.
please guide.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <vector>
using std::vector;

class MyClass { .... };

vector<MyClass> myVector( 100, MyClass() );
/* myVector now contains 100 objects of type MyClass, built with the default constructor */

vector<MyClass> myVector2;
// MyVector2 is empty

myVector2.assign( 100, MyClass() );

// My Vector2 now contains 100 objects of type MyClass, built with default ctor


There's nothing here you couldn't learn from http://www.cplusplus.com/reference/stl/vector/
Thanks a lot nonzenze.
Topic archived. No new replies allowed.