У меня проблемы с инициализацией базы данных, но я не могу понять, что это такое. Эта программа компилируется без ошибок, но всегда сбой при выполнении. Любая идея, что не так внутри функции initialise_database?Использование вектора со структурами
#include <iostream>
#include <cstddef>
#include <cstdlib>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
struct Date
{
int day, month, year;
};
struct Grade
{
int s1, s2, s3, s4, s5, s6;
};
struct Student
{
bool free;
long studentID;
string fname;
string sname;
Date DOB, DOE, DOG;
Grade semester1, semester2;
};
void initialise_database(vector<Student>, int size); // initialize each free variable to free
int main(int argc, char** argv)
{
fstream fin;
char choice_readfile;
int rowcount;
int size;
cout << "Enter number of student:\n";
cin >> size;
vector<Student> BENG;
do //verify choice to read from file is Y,y or N,n
{
cout << "Do you wish to read from file (Y/N)? (file name must be named students.txt)" << endl; //choice for user to read from external file
cin >> choice_readfile;
while(cin.fail())
{
cin.clear();
cin.ignore(80,'\n');
cout << "Please Re-Enter choice" << endl;
cin >> choice_readfile; // choice to read from file
}
}
while(choice_readfile != 'Y' && choice_readfile != 'y' && choice_readfile != 'N' && choice_readfile != 'n');
if(choice_readfile == 'Y' || choice_readfile == 'y')
{
fin.open("students.txt", ios::in|ios::out); //opens mygrades.txt
if(fin.fail())
{
cout << "Error occured while opening students.txt" << endl;
exit(1);
}
fin.clear();
fin.seekg(0);
string line;
while(getline(fin, line)) //counts the rows in the external file
{
rowcount++;
}
cout << "Number of rows in file is " << rowcount << endl;
cout << size << " " << rowcount << endl;
}
size += rowcount;
int i=0;
initialise_database(BENG, size);
return 0;
}
void initialise_database(vector<Student> BENG, int size)
{
for(int i=0;i<size;i++)
{
BENG[i].free = false;
}
}
Большое вам спасибо! –