C++ vector of your own Type
#include <iostream> #include <vector> using namespace std; class Employee //from w w w .j a v a 2 s .c o m { public: string Name; string FireDate; int my; Employee(string aname, string s, int a) : Name(aname), FireDate(s), my(a) {} }; int main() { // A vector that holds strings vector<string> stringVector; stringVector.push_back(string("A")); stringVector.push_back(string("B")); stringVector.push_back(string("C")); cout << stringVector[0] << endl; cout << stringVector[1] << endl; cout << stringVector[2] << endl; // A vector that holds integers vector<int> intVector; intVector.push_back(1); intVector.push_back(2); intVector.push_back(3); cout << intVector[0] << endl; cout << intVector[1] << endl; cout << intVector[2] << endl; // A vector that holds Employee instances vector<Employee> empVector; empVector.push_back(Employee("Z","1", 50)); empVector.push_back(Employee("T","0", 40)); cout << empVector[0].Name << endl; cout << empVector[1].Name << endl; return 0; }