Deleting a vector object

I am currently trying to implement a delete function within my system, to allow my to delete an account from within the account vector array and I am unable to work out how to do it, I am a complete rookie when it comes to C++ so any help would be appreciated, I do fear that the way that I call my create Account and my create person function are stopping me from searching arrays, so is it possible to name a created object before putting it in the appropriate array.

#include<iostream>
#include<vector>
#include"Account.h"
#include"cheque.h"
#include"Person.h"
#include"CustomersArray.h"

void main(void)
{

string CustTitle;
string Custfirst;
string Custlast;
int CustNo;
string CustLocation;
Person* createPerson(int CustNo, string CustTitle, string Custfirst, string Custlast, string CustLocation);
int numSearch;
CustomerArray c("string");
Person p("string");
Person* test;
char ch;
void intro();
do
{

system("cls");
cout<<"\n\n\n\t---MAIN MENU---";
cout<<"\n\n\t01. CREATE NEW ACCOUNT";
cout<<"\n\n\t02. LIST ACCOUNTS";
cout<<"\n\n\t03. CREATE CUSTOMER";
cout<<"\n\n\t04. LIST CUSTOMERS";
cout<<"\n\n\t05. LIST CUSTOMERS ACCOUNTS";
cout<<"\n\n\t06. CREATE NEW ACCOUNT";
cout<<"\n\n\t07. DELETE ACCOUNT";
cout<<"\n\n\t08. EXIT";
cout<<"\n\n\tSelect Your Option (1-8) ";
cin>>ch;
system("cls");
switch(ch)
{
case '1':
int intialBalance;
int intialInterest;
int accNo;
cout << "\n\n\tPlease enter an Account Number: ";
cin >> accNo;
cout << "\n\n\tPlease enter an intial balance: ";
cin >> intialBalance;
cout << "\n\n\tPlease enter an interest rate: ";
cin >> intialInterest;
test->addAccount(new Account(intialBalance, intialInterest, accNo));
break;
case '2':
p.PrintAllAccounts();
break;
case '3':void intro();
cout << "\n\n\tPlease enter Customers Number: ";
cin >> CustNo;
cout << "\n\n\tPlease enter Customers title: ";
cin >> CustTitle;
cout << endl;
cout << "\n\n\tCustomers First Name: ";
cin >> Custfirst;
cout << endl;
cout << "\n\n\tCustomers Last Name: ";
cin >> Custlast;
cout << endl;
cout << "\n\n\tCustomers Date of Birth(ddmmyyyy): ";
cin >> CustLocation;
test = createPerson(CustNo, CustTitle, Custfirst, Custlast, CustLocation);
c.addCustomer(test);
break;
case '4':
c.CustPrint();
break;
case '5':
cout<<"\n\n\tEnter Customer No.: ";
cin >> numSearch;
c.searchAccount(numSearch);

break;
case '6':
//deposit(double amount);
cout<<"\n\n\tThanks for using bank managemnt system";
break;
case '7':
//Call delete method
break;
case '8':
cout<<"\n\n\tThanks for using bank managemnt system";
break;
default :cout<<"\a";
}
cin.ignore();
cin.get();
}while(ch!='8');
}

Person* createPerson(int CustNo, string CustTitle, string Custfirst, string Custlast, string CustLocation)
{
Person* p = new Person(CustNo, CustTitle, Custfirst, Custlast, CustLocation);
return p;
}

void intro()
{
cout<<"\n\n\n\t BANK";
cout<<"\n\n\tMANAGEMENT";
cout<<"\n\n\t SYSTEM";
cout<<"\n\n\n\nLiam Salt";
cout<<"\n\nFPCC++";
cin.get();
}

You have headers here I don't have access to, so I can't run your code. With that said, the syntax to remove an index from a vector is below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <vector>
using namespace std;

int main()
{
	vector<int> aVector(3);
	aVector[0] = 0;
	aVector[1] = 1;
	aVector[2] = 2;

	//Delete index 1
	aVector.erase(aVector.begin()+1);

	for (int i=0; i<aVector.size(); ++i)
		cout << aVector[i] << "\n";

	system("pause");
	return 0;
}
Topic archived. No new replies allowed.