Writing a bank program: need help with customer class

What I'm trying to do is create a customer class with a type customer that will contain customer information like name, account, etc. I tried setting up something similar to what I've seen in class, but as you'll see in the code below, when I make a pointer 'a' to a new customer with info inputted it outputs an address. Any idea what I'm doing wrong or maybe a better way to do it? Thanks

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
#include "std_lib_facilities.h"

class customer {
public:

	string first_name;
	string last_name;
	int account;

	customer(const string& fn, const string& ln, int acct)
		: first_name(fn),last_name(ln),account(acct) {}


private:
};	


/*void print_all(customer* fn, customer* ln, customer* acct)
{
	cout<<fn;
}*/

int main()
{
	
	customer* a= new customer("John","Doe",12);
	
	cout<<a<<"\n";

	keep_window_open();

}


00594610
Please enter a character to exit
Since a is a pointer, if you output a it will display the memory address that a is pointing to. In order to access the data that a points to, you must dereference it by putting *a instead of just a. However, you cannot simply put "cout << *a << "\n";". Unless you overload the << operator, something your class probably hasn't covered yet, this will not work. So, you have to output each variable of the class separately.
first_name and last_name are public members, so you could do:
 
cout << a->first_name << a->last_name <<"\n";


It saves you the trouble of overloading the << operator (though it might be good practice to do so anyway).
Oh awesome thank you!
Topic archived. No new replies allowed.