In modern C++ about the only time you should be using a plain array is if you need to handle a C string, i.e.
char mystring[10]
or if you need to interface with a C function that manipulates an array. Otherwise, 99% of the time you want a
std::vector
For example
#include <vector>
#include <iostream>
class person {
private:
std::string name;
int age;
public:
person(std::string nm, int a) : name(nm), age(a) {}
string get_name() { return name; }
int get_age() { return age; }
};
int main()
{
string name1[5]={"saad","zaman","arslan","qaiser","qasim"};
int age1[5]={20,21,24,23,25};
std::vector<person> people;
for(int i = 0; i < 5; ++i)
{
person p(name1[i], age1[i]);
people.push_back(p);
}
for(const auto p : people)
std::cout << p.get_name() << " " << p.get_age();
}
Better yet, you can initialize an of objects using the extended initializer syntax
std::vector<person> people = {
{"saad", 20},
{"zaman", 21},
{"arslan", 24},
{ "qaiser", 23},
{ "qasim", 25}
};
This does require C++ 11 or later, though.