Re: std streams and enum?

From: Chris Newton (chrisnewton_at_no.junk.please.btinternet.com)
Date: 12/22/03


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



Relevant Pages

  • Re: std streams and enum?
    ... Chris Newton wrote: ... >> switch ... > At the risk of making a complete fool of myself because this seems so ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Everyone got their generator ready?
    ... I have said it was not safe, that there was a risk to the linesman, but very much lower than you implied, and a greater risk to the family. ... I also agreed that the safest and proper method was to use a changeover switch and permanent wiring. ... Please remember this discussion is about the risk to a linesman because folk might have connected a generator to their house wiring without isolating it from the grid. ... Dick or Harry's electrician has ...
    (uk.business.agriculture)
  • Re: Everyone got their generator ready?
    ... This is just one incident to illustrate a point. ... are away and the wife gets the neighbour to switch the thing on. ... The risk *is* ...
    (uk.business.agriculture)
  • Re: VLANS in a DMZ - good idea?
    ... in the best of all worlds you should place each security zone on a physical ... >placing multiple vlans on the same switch including different zones is IMHO an acceptable ... >low probability risk that a switch might be compromised I feel it is better to not introduce ... As I rock, rock, rock, rock, rock the microphone ...
    (comp.security.firewalls)
  • Re: Logging in
    ... You can not log out if you're happy with the risk that someone else will ... For many home computers, including ... More annoying are Nokia mobile phones that, when you switch them off, ...
    (alt.usage.english)