Hey guys! Could you help me here?
I have a Data Base.txt file. It contains:
1. First question
answer1
answer2
answer3
answer4
2. Second question
answer1
answer2
answer3
answer4
and I have a structure in which I want to put the data from a file.
struct questions
{
char questions[MAX], answers[4][MAX];
} q[2];
I have used the code below, but I got nothing, just a black screen.
Code:
#include<fstream.h>
#include<stdlib.h>
int main()
{
int i,j;
ifstream fin;
fin.open("Data Base.txt",ios::in | ios::nocreate);
if(!fin)
cout<<"Error reading file";
while(!fin.eof())
{
for(i=0;i<2;i++)
{
fin.get(q[i].questions,MAX);
for(j=0;j<4;j++)
fin.get(q[i].answers[j],MAX);
}
}
fin.close();
MAX is a defined constant.