How to make a vector with my own type "customer"

I've made this class customer that has a vector of type customer. I'm trying to figure out is how to access the elements of a vector of that type. My customer type has strings and doubles. I know with arrays I would use "->" to get each element of the array but I don't know how with vectors. Right now my code will input the data (I think it does anyway) but when I see a vector like accts[0] it displays address. Any help would be greatly appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "std_lib_facilities.h"

class customer {
public:

	void print_all(customer* x);
	customer* new_accnt(int x);
	customer(string fn, string ln, double acct, int pin)
		: first_name(fn),last_name(ln),account(acct), pin_number(pin) {}
	string f_name() { return first_name; }
	string l_name() { return last_name; }
	double get_acct() { return account; }
	int get_pin() {return pin_number;}


	

private:
	string first_name;
	string last_name;
	double account;
	int pin_number;
};	



vector<customer*> accts(10);

int acct_num = 0;

void new_accnt(int x)
{
	string fn, ln;
	double act;


	cout<<"\nWhat is your first name?\n";
	cin>>fn;
	cout<<"\nWhat is your last name?\n";
	cin>>ln;
	cout<<"\nHow much are you going to deposit?\n";
	cin>>act;

	
	accts[x]=new customer(fn,ln,act,7895);

	cout<<accts[x];

	acct_num++;
	
	
	cout<<"\nYou are account number:"<<x<<"\n";

	return;
}

void print_all(customer* x)
{
	cout<< x->f_name() <<" "<< x->l_name()<<"\n"<<x->get_acct()<<"\n\n";
}

int main()
{
	char i;

	
	
        cout<<"Would you like to create a new account?\n(y/n)";
		cin>>i;

	while(i=='y')
	{
	new_accnt(acct_num);
	acct_num++;
	}

	keep_window_open();

}
I change some code.

This:
accts[x]=new customer(fn,ln,act,7895);

To this:
accts[x]=customer(fn,ln,act,7895);

Because I think the orginal made it an array and I don't want an array, I want a vector.
> but when I see a vector like accts[0] it displays address

that is because you declared accts as a vector of pointers to customers

vector<customer*> accts(10);

that is fine, but then you need to access the elements as *(accts[i])

Last edited on
Topic archived. No new replies allowed.