When I want to access a part of the vector (appointment) it won't allow it, for example simply adding:
cout << appointment[1];
will not work.
I also want this vector to be saved to my class (Appointment), so I can later remove elements of the vector. Would I be able to do this simply by declaring the vector in the class? i.e.
class Appointment
{
private:
vector <string> appointment;
}
This is my whole code:
void Appointment::loadAppointments()
{
ifstream Appointments;
string line;
vector <string> appointment;
int i = 1;
cout << "You have the following appointments:" << endl;
Appointments.open(DATAFILE);
if (Appointments.is_open())
{
// Read the file until it's finished, displaying lines as we go.
while (!Appointments.eof())
{
getline(Appointments, line, '\n');
appointment.push_back(line);
}
Appointments.close();
}
cout << "this is a test" << appointment[1] << endl;//This part will not function
}