無效MAIN1(){ 結構程序無法正常工作
struct student
{
string name = "bob";
int quizs;
int labs;
int midterms;
int finals;
int classs;
int grade;
};
student stude;
vector<student>stu;
vector<string>qui{"Quiz 1","Quiz 2","Quiz 3", "Quiz 4","Quiz 5","Quiz 6","Quiz 7","Quiz 8"," Quiz 9","Quiz 10",
"Quiz 11", "Quiz 12"};
vector<string>La{ "Lab1", "Lab2","Lab3", "Lab4", "Lab5", "Lab6", "Lab7", "Lab8", "Lab9", "Lab10", "Lab11", "Lab12",
"Lab13", "Lab14", "Lab15", "Lab16", "Lab17" };
vector<string>mid{ "Midterm 1", "Midterm 2" };
vector<string>fin{ "Final 1", "Final 2" };
for (int i = 0; i < 12; i++)
{
cout << "please enter your score for " << qui[i] << ": ";
cin >> stu[i].quizs;
}
}
我不能得到這個代碼工作。當我嘗試在MIcrosoft Visual工作室中運行它時,出現一個令人討厭的line1234錯誤,它表示向量下標超出範圍。 有人請幫忙。
你不能簡單地訪問'不存在使他們的創作的std :: VECTOR'元素。這是屬於關聯容器的行爲。您必須提前調整矢量大小,或者使用諸如['std :: vector :: emplace_back'](http://en.cppreference.com/w/cpp/container/vector/emplace_back)之類的方法推送新元素。 –
看看'stu'。首先有多少個元素? – NathanOliver
請比「不工作」更具體 – EJoshuaS