How can I convert my Array (Identification users [20]) into a Vector

#include <iostream>
#include <fstream>
#include <conio.h>
#include <cstdlib>
#include <vector>

using namespace std;

void savePeople();
void requireEntry();
void searchDatabase();
void loadPeople();
void addPerson();
void showPerson();
void removePerson();

struct Identification //function allows to enter in info when instructed to
{
string name;
string surname;
short age;
string phonenumber;
};

short peopleinDatabase;

Identification users[20];

int main(){

char test;
loadPeople();
do{
cout << "People in Database: " << peopleinDatabase << endl;
cout << "Press '1' to enter name." << endl;
cout << "Press '2' to view all individuals in the database" << endl;
cout << "Menu: "<< endl;
cout << "1. Add Individual" << endl;
cout << "2. Show All Individuals" << endl;
cout << "3. Save People to File" << endl;
cout << "4. Load People to File" << endl;
cout << "5. Search for Info in Database" << endl;
cout << "6. Remove person from database" << endl;
cout << endl;
test = getch(); // tells the console to wait until key is hit

switch(test)// will use as a directory of where to take the code if a user wants to do a certain thing
{
case '1':
addPerson();
break;
case '2':
showPerson();
break;
case '3':
savePeople();
break;
case '4':
loadPeople();
break;
case '5':
searchDatabase();
break;
case'6':
removePerson();
}
requireEntry();
system("cls");
} while(getch() != 27); //27 represents escape in ASCii table

return 0;
}
void requireEntry(){
cout << "Click Enter to continue" << endl;
while(getch() != 13); //allowss for different data pieces to not be skipped when entering in data 0
}
void addPerson(){ //function that will allow users to put in information for database
cout << "Enter name: ";
cin >> users[peopleinDatabase].name;

cout << "Enter surname: ";
cin >> users[peopleinDatabase].surname;

cout << "Enter age: ";
cin >> users[peopleinDatabase].age;

cout << "Enter phone-number: ";
cin >> users[peopleinDatabase].phonenumber;

peopleinDatabase++;
}
void searchDatabase(){
if (peopleinDatabase > 0)
{
string name;
cout << "Type up what you want to find" << endl;
cin >> name;

for(int i = 0; i < peopleinDatabase; i++){
if(name == users[i].name)
{
cout << "User index: " << (i+1) << endl;
cout << "Name: " << users[i].name << endl;
cout << "Surname: " << users[i].surname << endl;
cout << "Age: " << users[i].age << endl;
cout << "Phone-number: " << users[i].phonenumber << endl;
cout << endl;
}
}
}
else
cout << "No information in database" << endl;
}
void loadPeople(){
ifstream file("database.txt");

if (file.is_open())
{
file >> peopleinDatabase;
if (peopleinDatabase > 0 )
{
for (int i = 0; i < peopleinDatabase; i++)
{
file >> users[i].name;
file >> users[i].surname;
file >> users[i].age;
file >> users[i].phonenumber;
}
cout << "People were loaded in database." << endl;
}
else
cout << "Database is empty" << endl;
}
else
cout << "Database file could not be found" << endl;

}
void savePeople(){
ofstream file("database.txt");
if(file.is_open()){
file << peopleinDatabase << endl;

for (int i = 0; i < peopleinDatabase; i++)
{
file << users[i].name << endl;
file << users[i].surname << endl;
file << users[i].age << endl;
file << users[i].phonenumber << endl;
file << endl;
file.close();
}
}
else
cout << "File could not be saved" << endl;
}
void showPerson(){ // function that diplays how many people in database and their info
if(peopleinDatabase > 0)
{
for(int i = 0; i < peopleinDatabase; i++)
{
cout << "User index: " << (i+1) << endl;
cout << "Name: " << users[i].name << endl;
cout << "Surname: " << users[i].surname << endl;
cout << "Age: " << users[i].age << endl;
cout << "Phone-number: " << users[i].phonenumber << endl;
cout << endl;
}
}
else
cout << "There is no one is the database" << endl;
}
void removePerson(){
if(peopleinDatabase > 0)
{
long index;
cout << "Who do you want to remove? Type index #" << endl;
cin >> index;
if(peopleinDatabase >= index)
{
for(long key = index; key < peopleinDatabase; key++)
{
users[key-1].name = users[key].name;
users[key-1].surname = users[key].surname;
users[key-1].age = users[key].age;
users[key-1].phonenumber = users[key].phonenumber;
}
peopleinDatabase--;
savePeople();
}
else
cout << " No index matches the number " << index << endl;
}
else
cout << "There is nothing in database to remove" << endl;
}
Identification users[20];
becomes

vector<Identification> users(20). that is the only change you need to make when converting array to vectors. (well, and #include<vector> of course).
thank you so much!!
Topic archived. No new replies allowed.