Below I have marked where I am getting an issue on calling my getter function. I was told that I need to Overload this function, how would I go about doing this? Any help offered is much appreciated.
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
usingnamespace 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;
}
Hmmm, I see where you're getting at I do believe. To print out a vector would you need to iterate through each element and print it out like you would an array??