1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
void inserData()
{
int counter =0;
int count = 0;
string data[11];
string buffer;
string buffer2;
string student = "student";
string lecturer = "lecturer";
ifstream inData;
inData.open("data.txt");
if(!inData)
{
cout<< "error";
}
else
cout<<"File Opened. 1st Reading Now"<<endl;
stringstream iss;
while(!inData.eof())
{
getline(inData,buffer); //first read to find all the lecturers and students needed
iss.str(buffer);
getline(iss, buffer2,',' );
if (buffer2 == "lecturer")
{
LMax++;
}
if (buffer2 == "student")
{
SMax++;
}
iss.clear();
}
inData.close();
inData.open("data.txt");
if(!inData)
{
cout<< "error";
}
else
cout <<"File Opened. 2nd Reading Now"<<endl;
stringstream * ss;
ss = new stringstream [LMax+SMax];
while(!inData.eof())
{
getline(inData,buffer); //after getting line into buffer, transfer line into a variable ss
ss[count].str(buffer); //for each individual line to reuse. Because errors will happen if you don't
getline(ss[count],data[0],',' );//this part of the func will officially read the data and pass it to
if (data[0] == "lecturer") //insertLec and insertStd for input into arrays
{
for(int x=1; x<8; x++)
{
getline(ss[count],data[x],',' );
}
insertLec(data[1],data[2],data[3],data[4],data[5],data[6],data[7]);
Lcounter++;
}
if (data[0] =="student")
{
for (int a=1; a<11;a++)
{
getline(ss[count],data[a],',' );
}
insertStd(data[1],data[2],data[3],data[4],data[5],data[6],data[7],data[8],data[9],data[10]);
Scounter++;
}
count++;
}
inData.close();
delete[] ss;
}
|