我只是 C++ 的初学者,我正在尝试让一些向量为我的程序工作,因为我正在尝试编写一个允许用户从文件中添加/编辑/删除以前条目的程序。问题是我无法让我的设置器与向量一起正常工作。我不确定我到底做错了什么。
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
class DVD
{
public:
//Default constructor
DVD();
//Class members
vector<string> name[5];
vector<string> length[5];
vector<string> actora[5];
vector<string> actorb[5];
vector<string> year[5];
//Function to set and get DVD Name
void setDVDname(vector<string> name)
{
DVDname[5]=name[5];
}
vector<string> getDVDname()
{
return DVDname;
}
//Function to set and get DVD length
void setDVDlength(vector<string> length)
{
DVDlength=length;
}
vector<string> getDVDlength()
{
return DVDlength;
}
//Function to get and get DVD year
void setDVDyear(vector<string> year)
{
DVDyear=year;
}
vector<string> getDVDyear()
{
return DVDyear;
}
//Function to get and set DVD Actor Alpha
void setDVDactorA(vector<string> actora)
{
DVDactorA=actora;
}
vector<string> getDVDactorA()
{
return DVDactorA;
}
//Function to get and set DVD Actor Bravo
void setDVDactorB(vector<string> actorb)
{
DVDactorB=actorb;
}
vector<string> getDVDactorB()
{
return DVDactorB;
}
protected:
private:
//Variables to hold DVD information
vector<string> DVDname[5];
vector<string> DVDlength[5];
vector<string> DVDactorA[5];
vector<string> DVDactorB[5];
vector<string> DVDyear[5];
};