Why can't I print my getter to the screen?

I have highlighted below in a comment where I am receiving my error. For some reason I cannot print my getter to the screen.

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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
 #include <iostream>
#include <vector>
#include <string>
#include <fstream>
using namespace std;

class Person
{
private:

	vector<string> this_name;
	vector<int> this_number;
	vector<string> this_address;

public:

	// getters

	vector<string> get_Name() const      //const  states that the method will not change any value within the class.
	{
		return this_name;
	}
	vector<string> get_Address()  const
	{
		return this_address;
	}
	vector<int> get_PhoneNumber() const 
	{
		return this_number;
	}

	// setters

	void set_Name(vector<string> N)
	{ 
		this_name = N; 

	}
	void set_Address(vector<string> A)
	{
		this_address = A;
	}
	void set_PhoneNumber(vector<int> P)
	{
		this_number = P;
	}
};



int main()
{
	
	Person Name;
	Person Address;
	Person PhoneNumer;
	string x;
	vector<string> all_addresses;
	int Answer;
	int z;

	ifstream datain;
	ofstream dataout;

	dataout.open("Address Book.dat");

	cout << "Please type 1 to enter addresses or 0 to exit: ";
	cin >> Answer;

	while (Answer == 1)
	{
		int v = 0;
		cout << "How many addresses would you like to enter?: ";
		cin >> z;
		cin.ignore();

		while (v < z)
		{
	
			cout << "Enter 1 address: ";
			getline(cin, x);


			all_addresses.push_back(x); // takes each string and pushes it to the end of the vector. This is how we make our vector of strings
		    Address.set_Address(all_addresses); // sets your vector of addresses to the set_Address setter.
			cout << Address.get_Address(); // *********ERRROR IS HERE*************
			v++;
		}

		cout << "Please type 1 to enter an address or 0 to exit: ";
		cin >> Answer;
	}
		for (string a_address : all_addresses)
		{
			dataout << a_address << endl;
			cout << a_address << endl;
		}

	

	if (Answer == 0)
	{
		cout << "Program Terminating...";
		system("Pause");
		return 0;
	}
	
	system("Pause");
	return 0;
}
Last edited on
That function returns a vector object. So you are trying to print a vector of strings, not an individual string object. Either overload the insertion operator, or make your own print function.
Last edited on
Topic archived. No new replies allowed.