C++/UNABLE TO FETCH DATA FROM THE FILE ,WRITEN THROUGHT OBJECT
i am unable to compare the data enter by user and data in file writen through object, while runing function.
my program code as follow:-
public: char name;
cout<<"nenter name="; cin>>name;
cout<<"nenter code="; cin>>code;
cout<<"nenter cost"; cin>>cost;
void inventory:: writedata()
cout<<"enter the name=";
while(fin && flag==0)
//in condition statement i want to comare user enter data(nm(char)).
//with the data in file which is an object variable(name).
//if it found the name variable of oject in a file then it will proceed further.
cout<<"data does not exits in file";
cout<<"Enter details for itemnn";
*after writing the data i the file it is runing if we call the funtion check().
*after executing the program there is garbage value in the file "stock.dat".
*the file containing the data and then if we run only check() function by comenting the code of writing in file. then it will not compare.
i will be highly thankful to you.if you help me out.
The strcmp needs to compare c.name to nm.
You could use fin.read((char *)this, sizeof *this);
and then your strcmp will work.
The file has garbage as seen in an editor, but I assure you, the data in the file is as written. Note because you wrote a block of data in binary, the file may or may not be portable and read on another computer.
Hope this helps you finish!