Here's the program
Its a simple program that asks for a name and saves it in a dat file and can display it.
<code>
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<ctype.h>
using namespace std;
class struct{
private: char *empname
float bsal;
public: int getdata();
int write();
int display();
};
struct obj;
int struct::getdata()
{
cout<<"Enter employee Name"<<endl;
gets(obj.empname);
cout<<"Enter Basic Salary"<<endl;
cin>>bsal;
return 0;
}
int struct::write()
{
ofstream fout;
fout.open("database.dat",ios::out|ios::binary|ios::app)
if(!fout)
{
cout<<"File can not be opened"<<endl;
return 0;
}
else
{
char ch;
do{
cout<<"Enter Employee Details"<<endl;
obj.getdata();
fout.write((char*)&obj,sizeof(obj));
cout<<"Do you want to enter another record:"<<endl;
cin>>ch;
}
while(ch=='y'||ch=='Y')
}
fout.close();
return 0;
}
int struct::display()
{
ifstream fin;
fin.open("database.dat",ios::in|ios::binary);
if(!fin)
{
cout<<"The file can not be opened";
return 0;
}
else
{
while(fin)
{
fin.read((char*)&obj,sizeof(struct));
}</code>
I think I am getting mixed up with c++ standard syntaxes
I use dev c++ 5.5.3
errors are
line col message
8 7 expected identifier before 'struct'
14 13 multiple types in one declaration
16 13 'getdata' in namespace '::' does not name a type
16 21 expected unqualified-id before ')' token
25 13 'write' in namespace '::' does not name a type
25 19 expected unqualified-id before ')' token
I found another error that i cant keep a c++ keyword struct as a class name. Wait I am going to re post a simple version of this code so that you guys can check it.
See I have completely remade the code. Can you guys check if it is logically correct please. I will be very grateful.
It compiled successfully but output is absurd
main.cpp(23): error C4716: 'getdata' : must return a value
main.cpp(66): warning C4715: 'display' : not all control paths return a value
main.cpp(41): error C4716: 'write' : must return a value