Re: std streams and enum?
From: Chris Newton (chrisnewton_at_no.junk.please.btinternet.com)
Date: 12/22/03
- Next message: Chris Newton: "Re: Scripting Language Tutorial"
- Previous message: flipdog: "Re: Hash Table in C: need help"
- In reply to: Anthony Borla: "Re: std streams and enum?"
- Next in thread: Jeff Schwab: "Re: std streams and enum?"
- Reply: Jeff Schwab: "Re: std streams and enum?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 22 Dec 2003 17:22:02 +0000 (UTC)
Anthony Borla wrote...
> enum account_t {Zero, One, Two};
>
> std::ostream& operator<<(std::ostream& out, const account_t& t)
> {
> switch (t)
> {
> case Zero: out << "Zero"; break;
> case One: out << "One"; break;
> case Two: out << "Two"; break;
> default: out << "Unknown";
> }
> return out;
> }
>
> std::istream& operator>>(std::istream& in, account_t& t)
> {
> int accType;
>
> // Add error handling and stream cleanup ...
> in >> accType;
>
> switch (accType)
> {
> case 0: t = Zero; break;
> case 1: t = One; break;
> case 2: t = Two; break;
> // ...
> // ...
> }
>
> return in;
> }
At the risk of making a complete fool of myself because this seems so
obvious... Doesn't that write out the enumeration values as strings
("Zero", etc.) but try to read them in as if they had been written
numerically ("0", etc.), making these two operators incompatible?
Cheers,
Chris
- Next message: Chris Newton: "Re: Scripting Language Tutorial"
- Previous message: flipdog: "Re: Hash Table in C: need help"
- In reply to: Anthony Borla: "Re: std streams and enum?"
- Next in thread: Jeff Schwab: "Re: std streams and enum?"
- Reply: Jeff Schwab: "Re: std streams and enum?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|