Mail Archives: djgpp/1997/08/20/14:19:45
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 -