getting error in reading value for a class variable .

Here is code that I have written ,
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
class record
{
	char *name,*usn,*age,*sem,*branch;
public:
	record(void)
	{
		name=NULL;
		usn=NULL;
		age=NULL;
		sem=NULL;
		branch=NULL;
	}
	void pack(fstream & out);
	void unpack(fstream & out);
	void search_record (const char *usnno) const;
	void retrive_details (const char *usnno) const;
	void delete_record ( const char *usnno );
	void displayFile () const;
	void read(int no);
};

void record::read(int no)
{
	for(int i=0;i<no;i++)
	{
		cout<<"\nName:"; cin>>name;
		cout<<"\nUsn:"; cin>>usn;
		cout<<"\nage:"; cin>>age;
		cout<<"\nsem:"; cin>>sem;
		cout<<"\nbranch:"; cin>>branch;
		file1<<usn<<"|"<<i<<endl;
		file2<<i<<"|";
		pack(file2);
	}
}


I need to write the value that is read by the read function to a file . I have opened a file in main under a switch case statement. The error that i got is The code is unable to read data into an object . While reading itself I tried to display the content of the object . I didn't get any output for that and ofcourse it cannot write to the files 1 and 2.
Topic archived. No new replies allowed.