• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

C++ question

With class MailingLabel,
public:
//constructors etc.
void output( ostream&) const;
private:
char * name;
char * address;
int zipcode;



how do i print out name address and zip using the
void output (ostream&) const;
I dont get ostream
 
Originally posted by: RobDowneyJr
With class MailingLabel,
public:
//constructors etc.
void output( ostream&) const;
private:
char * name;
char * address;
int zipcode;



how do i print out name address and zip using the
void output (ostream&) const;
I dont get ostream

There are many problems here. First, if you can avoid it, never use "char *". Only use "char *" for performance issues or for interfacing with "C". You should use std::string instead. Second, the output method is not necessary, try defining an ostream operator.
ostream & operator<<(ostream &) or
friend ostream & operator<<(ostream &, const &myclass)

To answer your question directly:

void output(ostream &os)
{
os << name << " " << address;
}
 
Originally posted by: PCHPlayer
Originally posted by: RobDowneyJr
With class MailingLabel,
public:
//constructors etc.
void output( ostream&) const;
private:
char * name;
char * address;
int zipcode;



how do i print out name address and zip using the
void output (ostream&) const;
I dont get ostream

There are many problems here. First, if you can avoid it, never use "char *". Only use "char *" for performance issues or for interfacing with "C". You should use std::string instead. Second, the output method is not necessary, try defining an ostream operator.
ostream & operator<<(ostream &) or
friend ostream & operator<<(ostream &, const &myclass)

To answer your question directly:

void output(ostream &os)
{
os << name << " " << address;
}

well its a function header given by lab manual,
the example for the main function is

int main(){
MailingLabel aLabel;
MailingLabel client("Joe Smith", "Newark, DE", 19711);

aLabel.output(cout);
client.output(cout);
}

theres warning that say string literals are being converted to char*
but i dont think im supposed to change how the lab manual wrote this class header

MailingLabel(char*, char*, int); //2nd constructor

how do i print out blank lines between the output? endl and \n dont seem to work in there
 
Back
Top