🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2034

Re: istream weirdness

#2034
From: Steve Clamage
Date: Mon, 25 Sep 1995 17:39
27 lines
1868 bytes
In article KAA12047@netcom22.netcom.com, cpp@netcom.com (Robin Rowe) writes:
>When using istream, numbers aren't parsed consistently by different
>compilers. For instance, in g++ inputting "95 09 23" is parsed as
>{95,0,9,23}, while the SGI C++ compiler will read it as {95,9,23} as one
>would tend to expect. Which is right, and if the former how is this
>"feature" turned off to get the latter result? 

The question is whether the istream is initialized to decimal conversion
mode or not. If initialized to decimal mode, "09" is read as "9". If not,
the same rules as for literals in C or C++ is used: a leading "0X" or "0x"
means hex conversion, otherwise a leading "0" means octal conversion.
Thus, since "9" is not an octal digit, "09" is interpreted as two values,
"0" and "9", with istream input.

The draft standard section on iostreams is in severe disarray currently,
and I can't tell what the default should be. I don't remember what the
original AT&T documentation said what the default should be.

The solution is simple: set the conversion base explicitly to decimal
at program start if you want that as the default
	cin.setf(ios::dec, ios::basefield);
---
Steve Clamage, stephen.clamage@eng.sun.com
---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <446i9t$9m2@engnews2.Eng.Sun.COM>
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back
References: <199509241711.KAA12047@netcom22.netcom.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back
Date: 25 Sep 95 17:39:08 GMT
Approved: fjh@cs.mu.oz.au
From: clamage@Eng.Sun.COM (Steve Clamage)
Newsgroups: comp.std.c++
Subject: Re: istream weirdness
X-Original-Date: 25 Sep 1995 15:36:29 GMT
Organization: Sun Microsystems Inc.
Message-ID: <446i9t$9m2@engnews2.Eng.Sun.COM>
References: <199509241711.KAA12047@netcom22.netcom.com>
Reply-To: clamage@Eng.Sun.COM