请帮我填充动态数组(for loop)
我需要一种方法来访问数组中的其他成员,例如title
,grade
,name
和age
我在填写时遇到错误
我想我应该做点像
cin >> C[i]. //I don't know what to write here
Student::Student(string a, int b, int c) : Person(a, b)
{
/*
my problem is how to open a dynamic array of Courses.
And how to fill them
*/
for (int i = 0; i < numberOfCourses; i++)
{
// dynamic array goes here!
}
}
答案 0 :(得分:1)
解决方案是声明新变量并由用户输入,如
if (cin >> title >> grade >> name >> age)
{
// use values
} else
{
// handle errors
}
然后在for循环中
C[i] = new Course(title, grade, ... );