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.eo f())
{
cout<<stu_file. name;
cout<<stu_file. studiengang;
cout<<stu_file. gesamtnote;
}
else
if(!stu_file.eo f())
{
cout<<"Student Name:"<<stu_fil e.name;
cout<<"Student Studiengang:"<< stu_file.studie ngang;
cout<<"Student Result:"<<stu_f ile.gesamtnote;
}
}
-------------------------------------------------
//my complete code
#include<iostre am.h>
#include<fstrea m.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(matrikel nummer, matn);
//strcpy(gesamtno te, "notcompleted") ;
}
friend istream &operator>>(ist ream &stream, Student &st);
friend ostream &operator<<(ost ream &stream, Student st);
};
//Saving into file
ostream &operator<<(ost ream &stream, Student st)
{
stream<<st.name <<"\n";
stream<<st.vorn ame <<"\n";
stream<<st.ort< <"\n";
stream<<st.matr ikelnummer<<"\n ";
stream<<strcpy( st.gesamtnote," notcompleted")< <"\n";
return stream;
}
istream &operator>>(ist ream &stream, Student &st)
{
cout<<"enter the Student Name :";
stream>>st.name ;
cout<<"enter the Student Vorname :";
stream>>st.vorn ame;
cout<<"enter Studnet Ort :";
stream>>st.ort;
cout<<"enter the Student Matrikelnummer :";
stream>> st.matrikelnumm er;
cout<<"enter the Studiengang :";
stream>>st.stud iengang;
//stream>>st.gesa mtnote;
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<<(ost ream &stream, Student pr);
//friend istream &operator>>(ist ream &stream, Student &pr);
};
main()
{
Student stud;
Professor prof;
char c;
// this file for Student data
fstream stu_file("Stude nt.txt", ios::in | ios::out|ios::a pp);
if(!stu_file)
{
cout<<" it is not posible to open a file";
return 1;
}
// this file for Professor
fstream pro_file("profe ssor.txt", ios::in | ios::out |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.eo f())
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.eo f())
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.eo f())
{
cout<<stu_file. name;
cout<<stu_file. studiengang;
cout<<stu_file. gesamtnote;
}
else
if(!stu_file.eo f())
{
cout<<"Student Name:"<<stu_fil e.name;
cout<<"Student Studiengang:"<< stu_file.studie ngang;
cout<<"Student Result:"<<stu_f ile.gesamtnote;
}
}
stu_file.clear( );
//cout<<end1;
break;
case '6':
break;
case '7':
stu_file.close( );
pro_file.close( );
return 0;
}
}
} 4 1379
Hi,
your stu_file is of type "fstream". You want to use variables of type
"Student", thus you should stream(load) the data from stu_file into a
Student structure and then display it's content.
I've fixed your code so it compiles now. I have not checked if it
work, but you see the point, hopefully.
Search for "GF:"
Code:
// Main
#include <windows.h>
#include<iostre am.h>
#include<fstrea m.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(matrikel nummer, matn);
//strcpy(gesamtno te, "notcompleted") ;
}
friend istream &operator>>(ist ream &stream, Student &st);
friend ostream &operator<<(ost ream &stream, Student st);
};
//Saving into file
ostream &operator<<(ost ream &stream, Student st)
{
stream<<st.name <<"\n";
stream<<st.vorn ame <<"\n";
stream<<st.ort< <"\n";
stream<<st.matr ikelnummer<<"\n ";
stream<<strcpy( st.gesamtnote," notcompleted")< <"\n";
return stream;
}
istream &operator>>(ist ream &stream, Student &st)
{
cout<<"enter the Student Name :";
stream>>st.name ;
cout<<"enter the Student Vorname :";
stream>>st.vorn ame;
cout<<"enter Studnet Ort :";
stream>>st.ort;
cout<<"enter the Student Matrikelnummer :";
stream>> st.matrikelnumm er;
cout<<"enter the Studiengang :";
stream>>st.stud iengang;
//stream>>st.gesa mtnote;
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<<(ost ream &stream, Student pr);
//friend istream &operator>>(ist ream &stream, Student &pr);
};
main()
{
Student stud;
Professor prof;
char c;
// this file for Student data
fstream stu_file("Stude nt.txt", ios::in | ios::out|ios::a pp);
if(!stu_file)
{
cout<<" it is not posible to open a file";
return 1;
}
// this file for Professor
fstream pro_file("profe ssor.txt", ios::in | ios::out |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.eo f())
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.eo f())
cout<<ch1;
}
pro_file.clear( );
//cout<<end1;
break;*/
case '5':
stu_file.seekg( 0, ios::beg);
while(!stu_file .eof())
{
// GF: Temporäre Variable anlegen
Student depperl;
// GF: Daten von stu_file stream auf die Variable lesen
stu_file >> depperl;
// if(stu_file.get (ort) == "berlin" )
if(!stu_file.eo f())
{
// GF: Variablendaten anzeigen.
cout<<depperl.n ame;
cout<<depperl.s tudiengang;
cout<<depperl.g esamtnote;
}
else
if(!stu_file.eo f())
{
Student depperl;
stu_file >> depperl;
cout<<"Student Name:"<<depperl .name;
cout<<"Student Studiengang:"<< depperl.studien gang;
cout<<"Student Result:"<<deppe rl.gesamtnote;
}
}
stu_file.clear( );
//cout<<end1;
break;
case '6':
break;
case '7':
stu_file.close( );
pro_file.close( );
return 0;
}
}
}
reddy wrote: 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
[snip]
//my complete code #include<iostre am.h> #include<fstrea m.h> #include<string .h>
The above headers are deprecated. Remove the '.h'.
//using namespace std;
class PersonalDetails // creating Base calss { public: //variables char name[25]; char vorname[25]; char ort[25];
};
Why are you using char arrays?
Use std::string class instead.
If you must use a fixed size char array, then use named
constants for the size:
class PersonalDetails
{
public:
enum {MAX_NAME_LENGT H = 25};
char name[MAX_NAME_LENGTH];
char vorname[MAX_NAME_LENGTH];
char ort[MAX_NAME_LENGTH];
}
Also, you should put in methods for input and output
of these values into this class.
class Student : public PersonalDetails //creating stdent class derived from PersonalDetails calss { public: // variables for student char matrikelnummer[25]; char studiengang[25]; char gesamtnote[25];
See above comments about strings & named constants.
public: Student() { } //display to screen Student( char *n, char *vn, char *or,char *matn) { strcpy(name, n); strcpy(vorname, vn); strcpy(ort, or); strcpy(matrikel nummer, matn); //strcpy(gesamtno te, "notcompleted") ; }
With std::string, you could just use an initialization list:
Student(const string& n, const string& vn,
const string& or, const string& matn)
: PersonalDetails (n, vn, or, matn)
{
} friend istream &operator>>(ist ream &stream, Student &st); friend ostream &operator<<(ost ream &stream, Student st);
These should also be defined in PersonalDetails .
}; //Saving into file ostream &operator<<(ost ream &stream, Student st) { stream<<st.name <<"\n"; stream<<st.vorn ame <<"\n"; stream<<st.ort< <"\n"; stream<<st.matr ikelnummer<<"\n "; stream<<strcpy( st.gesamtnote," notcompleted")< <"\n"; return stream; } istream &operator>>(ist ream &stream, Student &st) {
cout<<"enter the Student Name :"; stream>>st.name ; cout<<"enter the Student Vorname :"; stream>>st.vorn ame; cout<<"enter Studnet Ort :"; stream>>st.ort; cout<<"enter the Student Matrikelnummer :"; stream>> st.matrikelnumm er; cout<<"enter the Studiengang :"; stream>>st.stud iengang; //stream>>st.gesa mtnote; cout<<"/n"; return stream;
How are you checking that the char arrays are not overflowed.
For example, if I enter a student name that is 30 chars long,
what will happen? } 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); }
Again, see note about std::string and initialization lists. //friend ostream &operator<<(ost ream &stream, Student pr); //friend istream &operator>>(ist ream &stream, Student &pr); };
main()
Close. This should be:
int main(void)
{ Student stud; Professor prof; char c;
// this file for Student data fstream stu_file("Stude nt.txt", ios::in | ios::out|ios::a pp); if(!stu_file) { cout<<" it is not posible to open a file"; return 1;
Use EXIT_FAILURE, from <cstdlib>, instead of 1.
Also, state the file name in the output.
**** Note that stu_file is of type fstream. ******
**** This will help out later in the program. *****
} // this file for Professor fstream pro_file("profe ssor.txt", ios::in | ios::out |ios::app); if(!pro_file) { cout<<"it is not posible to open Professer file"; return 1;
Use EXIT_FAILURE, from <cstdlib>, instead of 1.
Also, state the file name in the output.
} 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');
You could use an unsigned int for the choice.
switch(c) {
[snip]
case '5': stu_file.seekg( 0, ios::beg); while(!stu_file .eof()) { if(stu_file.get (ort) == "berlin" )
Where is the variable 'ort' defined?
if(!stu_file.eo f()) { cout<<stu_file. name; cout<<stu_file. studiengang; cout<<stu_file. gesamtnote;
As I stated above, "stu_file" is of fstream, not
Student. You will need to use your variable of
type 'Student' (stud) here.
} else if(!stu_file.eo f()) { cout<<"Student Name:"<<stu_fil e.name; cout<<"Student Studiengang:"<< stu_file.studie ngang; cout<<"Student Result:"<<stu_f ile.gesamtnote; }
The variable 'stu_file' is of type fstream (see the
'if' statement). Use 'stud' instead.
} stu_file.clear( ); //cout<<end1; break; case '6': break; case '7': stu_file.close( ); pro_file.close( ); return 0; } } }
--
Thomas Matthews
C++ newsgroup welcome message: http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.l earn.c-c++ faq: http://www.raos.demon.uk/acllc-c++/faq.html
Other sites: http://www.josuttis.com -- C++ STL Library book su***********@y ahoo.com (reddy) wrote in message news:<3d******* *************** ****@posting.go ogle.com>... 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
Try writing a small program first. You added code for a professor
without testing the student code first. This complexity means you
can't find your own bugs.
The bug is in fact very simple. class fstream doesn't have a member
called name. class Student does. This means one of two things:
Your object stu_file should have had type Student, or
you should have used your stud object which has the correct type.
Regards,
Michiel Salters
Thomas Matthews wrote: //my complete code #include<iostre am.h> #include<fstrea m.h> #include<string .h> The above headers are deprecated. Remove the '.h'.
Not so fast. <string.h> is the only one deprecated, the others are
nonstandard. Also, <string.h> should be updated with <cstring> and not
<string>.
Brian Rodenborn This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Mike |
last post by:
I am sure that I am making a simple boneheaded mistake and I would
appreciate your help in spotting in. I have just installed
apache_2.0.53-win32-x86-no_ssl.exe
php-5.0.3-Win32.zip
Smarty-2.6.7.tar.gz
on a system running WindowsXP SP2.
Apache and PHP tested out fine. After adding Smarty, I ran the
following http://localhost/testphp.php
|
by: Xah Lee |
last post by:
here's a large exercise that uses what we built before.
suppose you have tens of thousands of files in various directories.
Some of these files are identical, but you don't know which ones are
identical with which. Write a program that prints out which file are
redundant copies.
Here's the spec.
--------------------------
The program is to be used on the command line. Its arguments are one or
|
by: Tom Lee |
last post by:
Hi,
I'm new to .NET 2003 compiler. When I tried to compile my
program using DEBUG mode, I got the following errors in the
C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7
\include\xdebug file as folows. I need help to resolve
them ASAP:
cl /c /nologo /MDd /W3 /Od /GR /GM /Zi /GX /D "_DEBUG" /D "
WIN32" /D "_W
INDOWS" /D "_WINDLL" /D "_AFXDLL" /D "_MBCS" /D "_USRDLL" /
|
by: JKop |
last post by:
Here's what I know so far:
You have a C++ project. You have source files in it. When you go to
compile it, first thing the preprocessor sticks the header files into
each source file.
So now you have your ".cpp" files all ready, without any "#include"
or "#define" in them.
Let's assume that there's 2 source files in this project, "a.cpp" and
|
by: pooja |
last post by:
Suppose i have created a class c1 with f1()in c1.cpp
and included this c1.cpp in file1.cpp file , which is also having
main() by giving the statement #include "c1.cpp".
the same i can do by using header file. i can create a class c1 with
f1() in c1.h and include this c1.h in file1.cpp by giving the statement
#include "c1.h"
tell me that what exactly is the difference between c1.h and c1.cpp?
Since they both are doing the same things.
| |
by: ambika |
last post by:
Iam just trying to know "c".
And I have a small doubt about these header files.
The header files just contain the declaration part...Where is the
definition for these declarations written??And how does that get
linked to our program when we run it??I would appreciate any helpful
info..And I would like to thank you for that in advance
-ambika
|
by: Daniel Billingsley |
last post by:
Ok, I wanted to ask this separate from nospam's ridiculous thread in hopes
it could get some honest attention.
VB6 had a some simple and fast mechanisms for retrieving values from basic
text files, which in turn could be simply and easily maintained with
notepad.
I understand the benefits of XML, really, but in the case of configuration
files it seems it is almost always nothing more than unnecessary complexity,
both in accessing them...
|
by: UJ |
last post by:
Folks,
We provide custom content for our customers. Currently we put the files on
our server and people have a program we provide that will download the
files. These files are usually SWF, HTML or JPG files. The problem as I see
it - if you know the name of the file, you could download it off the server
(currently we are using an HTTP/Get but I'm going to be using WebClient in
the new version.)
If there any way to password protect the...
|
by: wal |
last post by:
How does one attach files to emails using libgmail? The following code
http://pramode.net/articles/lfy/fuse/4.txt
works fine when said files are simple text files, but it failes as soon as
the files are wild binary files, even attaching the source of an email in a
text file (.eml files) failes.
What am I missing here? Any hints?
The output I get when attemting to send binary files using the code above
is pasted below.
have fun,
|
by: aRTx |
last post by:
I have try a couple of time but does not work for me
My files everytime are sortet by NAME.
I want to Sort my files by Date-desc.
Can anyone help me to do it?
The Script
<?
/*
ORIGJINALI
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |