Mail Archives: djgpp/1997/08/24/01:34:17
> slight problem.
> You need to add the function
>
> struct node {
> int number;
> unsigned char age;
> char *name;
> node *next;
>
> friend ostream & operator(ostream &,const node&);
> }
Thank you for telling me the slight problem. You have prevented me from
hours of frustration and debugging.
However, I am sure that your code cannot pass the compiler, too.
friend ostream & operator(ostream &,const node&);
How come there is not any punctuation between the operator keyword and
the left parenthesis?
Einstein
einstein DOT lam AT usa DOT net
i96csm AT river DOT tay DOT ac DOT uk wrote:
>
> In article <33F98A99 DOT 7AEC324C AT usa DOT net>, Einstein <einstein DOT lam AT usa DOT net> writes:
> > struct node {
> > int number;
> > unsigned char age;
> > char *name;
> > node *next;
> > }
> >
> > If you want to save this struct, write this operator:
> > ostream& operator <<( node src );
> >
> > Assumptions:
> > You are using C++.
> > You can get the string length by some means. For instances, size_t strlen(
> > const char *string );
> >
> > Remarks:
> > If the variable length string is allocated using the new operator, do not
> > use the old char* and allocate the memory every time.
> > Remember to save the string length.
> >
> > Einstein
> > einstein DOT lam AT usa DOT net
> >
> >
> >
> >
>
> slight problem.
> You need to add the function
>
> struct node {
> int number;
> unsigned char age;
> char *name;
> node *next;
>
> friend ostream & operator(ostream &,const node&);
> }
>
> and define it as
>
> ostream & operator(ostream & out,const node & n)
> {
> out << n.number << '\n' << (int) n.age << '\n'
> << n.age << 'n'
>
> if (n.next == NULL)
> out << "NULL\n";
> else
> out << (n.next)->number << '\n';
>
> return out;
> }
>
> But this is C++, and doesn't help if you are using C
> --
> ___ .
> / /|\ /|
> / / | \ / | Colin S. Miller
> / \ | v | csmiller AT iname DOT com
> | \| |
> | \ | PgDip/MSc Software Engineering
> | |\ | University of Abertay
> \ | \ | (01382) 308000 ext 2800
> \ | / |
> \___/ |
>
- Raw text -