R
reddy
Hai,
in my program i am creating two files, and displaying that files, but
i am getting some errors like, "name' : is not a member of 'fstream'"?
in that i am not getting some fields from what i created file ? i want
to display the some fields only with one condition, how , please give
the your answer? in below i am pasting complete code. please check in
main()
{
..............
case '5':
.............
}
thanks alot
ready
-----------------------------
// this part i need to correct
stu_file.seekg(0, ios::beg);
while(!stu_file.eof())
{
if(stu_file.get(ort) == "berlin" )
if(!stu_file.eof())
{
cout<<stu_file.name;
cout<<stu_file.studiengang;
cout<<stu_file.gesamtnote;
}
else
if(!stu_file.eof())
{
cout<<"Student Name:"<<stu_file.name;
cout<<"Student Studiengang:"<<stu_file.studiengang;
cout<<"Student Result:"<<stu_file.gesamtnote;
}
}
-------------------------------------------------
//my complete code
#include<iostream.h>
#include<fstream.h>
#include<string.h>
//using namespace std;
class PersonalDetails // creating Base calss
{
public:
//variables
char name[25];
char vorname[25];
char ort[25];
};
class Student : public PersonalDetails
//creating stdent class derived from PersonalDetails calss
{
public:
// variables for student
char matrikelnummer[25];
char studiengang[25];
char gesamtnote[25];
public:
Student() { }
//display to screen
Student( char *n, char *vn, char *or,char *matn)
{
strcpy(name, n);
strcpy(vorname, vn);
strcpy(ort, or);
strcpy(matrikelnummer, matn);
//strcpy(gesamtnote, "notcompleted");
}
friend istream &operator>>(istream &stream, Student &st);
friend ostream &operator<<(ostream &stream, Student st);
};
//Saving into file
ostream &operator<<(ostream &stream, Student st)
{
stream<<st.name <<"\n";
stream<<st.vorname <<"\n";
stream<<st.ort<<"\n";
stream<<st.matrikelnummer<<"\n";
stream<<strcpy(st.gesamtnote,"notcompleted")<<"\n";
return stream;
}
istream &operator>>(istream &stream, Student &st)
{
cout<<"enter the Student Name :";
stream>>st.name;
cout<<"enter the Student Vorname :";
stream>>st.vorname;
cout<<"enter Studnet Ort :";
stream>>st.ort;
cout<<"enter the Student Matrikelnummer :";
stream>> st.matrikelnummer;
cout<<"enter the Studiengang :";
stream>>st.studiengang;
//stream>>st.gesamtnote;
cout<<"/n";
return stream;
}
class Professor : public PersonalDetails
{
public:
// variables
char funktion[25];
public:
Professor() { }
Professor( char *pn, char *pvn, char *por,char *pfun)
{
strcpy(name, pn);
strcpy(vorname, pvn);
strcpy(ort, por);
strcpy(funktion, pfun);
}
//friend ostream &operator<<(ostream &stream, Student pr);
//friend istream &operator>>(istream &stream, Student &pr);
};
main()
{
Student stud;
Professor prof;
char c;
// this file for Student data
fstream stu_file("Student.txt", ios::in | ios:ut|ios::app);
if(!stu_file)
{
cout<<" it is not posible to open a file";
return 1;
}
// this file for Professor
fstream pro_file("professor.txt", ios::in | ios:ut |ios::app);
if(!pro_file)
{
cout<<"it is not posible to open Professer file";
return 1;
}
for(;
{
do
{
cout<<"1. for Enter Student Data\n";
cout<<"2. for Enter Professor Data\n";
cout<<"3. for Display the stednt details\n";
cout<<"4. for Display the Proffesor Details\n";
cout<<"5. for Who are commpleted \n";
cout<<"6. for Who are not completed \n";
cout<<"7. for Exit\n";
cout<<"\nEnter your choice";
cin>>c;
}while(c < '1' || c > '7');
switch(c)
{
case '1':
cin>>stud;
cout<<" Entry is:";
cout<<stud; // show on screen
stu_file << stud;// saveing in to the file
break;
/*case '2':
cin>>prof;
cout<<" Entry is:";
cout<<prof; // show on screen
pro_file << prof;// saveing in to the file
break;*/
case '3':
char ch;
stu_file.seekg(0, ios::beg);
while(!stu_file.eof())
{
stu_file.get (ch);
if(!stu_file.eof())
cout<<ch;
}
stu_file.clear();
//cout<< end1;
break;
/*case '4':
char ch1;
pro_file.seekg(0, ios::beg);
while(!pro_file.eof())
{
pro_file.get (ch1);
if(!pro_file.eof())
cout<<ch1;
}
pro_file.clear();
//cout<<end1;
break;*/
case '5':
stu_file.seekg(0, ios::beg);
while(!stu_file.eof())
{
if(stu_file.get(ort) == "berlin" )
if(!stu_file.eof())
{
cout<<stu_file.name;
cout<<stu_file.studiengang;
cout<<stu_file.gesamtnote;
}
else
if(!stu_file.eof())
{
cout<<"Student Name:"<<stu_file.name;
cout<<"Student Studiengang:"<<stu_file.studiengang;
cout<<"Student Result:"<<stu_file.gesamtnote;
}
}
stu_file.clear();
//cout<<end1;
break;
case '6':
break;
case '7':
stu_file.close();
pro_file.close();
return 0;
}
}
}
in my program i am creating two files, and displaying that files, but
i am getting some errors like, "name' : is not a member of 'fstream'"?
in that i am not getting some fields from what i created file ? i want
to display the some fields only with one condition, how , please give
the your answer? in below i am pasting complete code. please check in
main()
{
..............
case '5':
.............
}
thanks alot
ready
-----------------------------
// this part i need to correct
stu_file.seekg(0, ios::beg);
while(!stu_file.eof())
{
if(stu_file.get(ort) == "berlin" )
if(!stu_file.eof())
{
cout<<stu_file.name;
cout<<stu_file.studiengang;
cout<<stu_file.gesamtnote;
}
else
if(!stu_file.eof())
{
cout<<"Student Name:"<<stu_file.name;
cout<<"Student Studiengang:"<<stu_file.studiengang;
cout<<"Student Result:"<<stu_file.gesamtnote;
}
}
-------------------------------------------------
//my complete code
#include<iostream.h>
#include<fstream.h>
#include<string.h>
//using namespace std;
class PersonalDetails // creating Base calss
{
public:
//variables
char name[25];
char vorname[25];
char ort[25];
};
class Student : public PersonalDetails
//creating stdent class derived from PersonalDetails calss
{
public:
// variables for student
char matrikelnummer[25];
char studiengang[25];
char gesamtnote[25];
public:
Student() { }
//display to screen
Student( char *n, char *vn, char *or,char *matn)
{
strcpy(name, n);
strcpy(vorname, vn);
strcpy(ort, or);
strcpy(matrikelnummer, matn);
//strcpy(gesamtnote, "notcompleted");
}
friend istream &operator>>(istream &stream, Student &st);
friend ostream &operator<<(ostream &stream, Student st);
};
//Saving into file
ostream &operator<<(ostream &stream, Student st)
{
stream<<st.name <<"\n";
stream<<st.vorname <<"\n";
stream<<st.ort<<"\n";
stream<<st.matrikelnummer<<"\n";
stream<<strcpy(st.gesamtnote,"notcompleted")<<"\n";
return stream;
}
istream &operator>>(istream &stream, Student &st)
{
cout<<"enter the Student Name :";
stream>>st.name;
cout<<"enter the Student Vorname :";
stream>>st.vorname;
cout<<"enter Studnet Ort :";
stream>>st.ort;
cout<<"enter the Student Matrikelnummer :";
stream>> st.matrikelnummer;
cout<<"enter the Studiengang :";
stream>>st.studiengang;
//stream>>st.gesamtnote;
cout<<"/n";
return stream;
}
class Professor : public PersonalDetails
{
public:
// variables
char funktion[25];
public:
Professor() { }
Professor( char *pn, char *pvn, char *por,char *pfun)
{
strcpy(name, pn);
strcpy(vorname, pvn);
strcpy(ort, por);
strcpy(funktion, pfun);
}
//friend ostream &operator<<(ostream &stream, Student pr);
//friend istream &operator>>(istream &stream, Student &pr);
};
main()
{
Student stud;
Professor prof;
char c;
// this file for Student data
fstream stu_file("Student.txt", ios::in | ios:ut|ios::app);
if(!stu_file)
{
cout<<" it is not posible to open a file";
return 1;
}
// this file for Professor
fstream pro_file("professor.txt", ios::in | ios:ut |ios::app);
if(!pro_file)
{
cout<<"it is not posible to open Professer file";
return 1;
}
for(;
{
do
{
cout<<"1. for Enter Student Data\n";
cout<<"2. for Enter Professor Data\n";
cout<<"3. for Display the stednt details\n";
cout<<"4. for Display the Proffesor Details\n";
cout<<"5. for Who are commpleted \n";
cout<<"6. for Who are not completed \n";
cout<<"7. for Exit\n";
cout<<"\nEnter your choice";
cin>>c;
}while(c < '1' || c > '7');
switch(c)
{
case '1':
cin>>stud;
cout<<" Entry is:";
cout<<stud; // show on screen
stu_file << stud;// saveing in to the file
break;
/*case '2':
cin>>prof;
cout<<" Entry is:";
cout<<prof; // show on screen
pro_file << prof;// saveing in to the file
break;*/
case '3':
char ch;
stu_file.seekg(0, ios::beg);
while(!stu_file.eof())
{
stu_file.get (ch);
if(!stu_file.eof())
cout<<ch;
}
stu_file.clear();
//cout<< end1;
break;
/*case '4':
char ch1;
pro_file.seekg(0, ios::beg);
while(!pro_file.eof())
{
pro_file.get (ch1);
if(!pro_file.eof())
cout<<ch1;
}
pro_file.clear();
//cout<<end1;
break;*/
case '5':
stu_file.seekg(0, ios::beg);
while(!stu_file.eof())
{
if(stu_file.get(ort) == "berlin" )
if(!stu_file.eof())
{
cout<<stu_file.name;
cout<<stu_file.studiengang;
cout<<stu_file.gesamtnote;
}
else
if(!stu_file.eof())
{
cout<<"Student Name:"<<stu_file.name;
cout<<"Student Studiengang:"<<stu_file.studiengang;
cout<<"Student Result:"<<stu_file.gesamtnote;
}
}
stu_file.clear();
//cout<<end1;
break;
case '6':
break;
case '7':
stu_file.close();
pro_file.close();
return 0;
}
}
}