Прочитать файл и добавить элементы в новый массив в C++
Всем привет. Извиянусь за мой руский язык. Я хочу объявить динамический массив, и следующая вещь - иметь возможность читать файл и добавлять элементы в массив Student. Вроде код компилирует, но результата не вижу. Ваше предложение приветствуется.
int main(int argc, char** agrv)
{
if(argc < 2 || argc > 2)
{
cerr << "You have to provide a file" << endl;
return -1;
}
string myFile = agrv[1];
ifstream file(myFile.c_str());
if (!file)
{
cerr << "Error, file do not exist" << endl;
return -1;
}
Student students; // Declared in other file
// File contains Number-String-String-String
string number_student, name_student, surname_student, code_student;
double number_file_student;
// Declare an new array
DynamicArray<Student>students;
while(file >>number_file_student >> name_student >> surname_student >> code_student)
{
students.add(student);
}
for(int i = 0; i < students.size(); i++)
cout << students[i] << endl;