classes n file handling

facing errors:why am i facing fatal error

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
  #include <iostream>
#include <fstream>
#include <cstring>
using namespace std;

//Class StudentInfo
class StudentInfo
{
//Data members
char VUID;
char campusID;
char Studentname;
char FatherName;

public:
//Parameterized Constructor 
StudentInfo(char vu_Id, char c_Id, char s_Name, char f_Name)
{
VUID=vu_Id;
campusID=c_Id;
Studentname=s_Name;
FatherName=f_Name;}
void storeFile()
{
cout << "All the data members are stored in file." << endl;
//Creating or opening file for write
ofstream outFile;
char outputFileName[]= "record.txt";
outFile.open(outputFileName, ios::out);
if(!outFile)
{
cout << "\n Unable to open file." << endl;

}
else
{
//Writting the data to file
outFile << VUID; 
outFile << endl;
outFile << campusID;
outFile << endl;
outFile << Studentname;
outFile << endl;
outFile << FatherName;

}
}
void display()
{
//Open file for read
ifstream infile;
char inputFileName[]="record.txt";
infile.open(inputFileName);
if(!infile)
{
cout << "\nCan't Open the file for read";
}
else
{
//Read the data from file and set the values to data members. 
cout << "Following is your data:" << endl;
cout << VUID << endl;
cout << campusID << endl;
cout << Studentname << endl;
cout << FatherName<<endl;
}

}

int main()
{
//Create StudentInfo object with parameterized constructor and calling storeFile and display methods.
StudentInfo obj(a,b,c,d);
obj.storeFile();
obj.display();

return 0;
}
Last edited on
The only errors that I can spot are:
1. You are not providing the member values to the constructor while instantiating the obj object.
2. In your display function the parameters are not being read from the file. The existing parameters of that particular object are being outputted.
Last edited on
will u plz correct it
 
StudentInfo obj('a','b','c','d');
facing "fatal error C1004: unexpected end of file found"
I am assuming that now you are able to compile your program.

After writing to the file, you need to flush out the buffer and close the file.
1
2
outFile << std::flush;
outFile.close();


After reading input also you need to close the file.


Last edited on
indentation is terrible, but it looks like you ain't put a ";" at the end of your class declaration.
Topic archived. No new replies allowed.