Article View: comp.std.c++
Article #2028istream weirdness
From: Robin Rowe
Date: Mon, 25 Sep 1995 02:02
Date: Mon, 25 Sep 1995 02:02
49 lines
1604 bytes
1604 bytes
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? (See test code below.)
A related problem is setw. Given input of "950923" one would like to use
is>>setw(2)>>x to parse it. However, setw has no effect on integers (tried
bc++ 3.1). What is the proper iostream way to accomplish the ubiquitous
task of parsing fixed length numeric fields?
Thanks.
Robin
-----
Robin Rowe cpp@netcom.com 408-626-6646 Carmel, CA
Rowe Technology C++ Design/Training Email for sample C++ Newsletter!
#include <iostream.h>
int main()
{ cout<<"Test cin. CTRL-D or CTRL-Z to quit.\n";
int x;
while(cin)
{ cin>>x; //input: "95 09 23" [Enter]
cout<<x<<endl;
}
return 0;
}
/* output g++:
95
0
9
23
*/
/* output SGI:
95
9
23
*/
---
[ 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:
<199509241711.KAA12047@netcom22.netcom.com>Path:
arc1-ca.pugleaf.net!in2.uu.net!bounce-backShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back Date: 25 Sep 95 02:02:36 GMT Approved: fjh@cs.mu.oz.au Organization: - Newsgroups: comp.std.c++ X-Original-Date: Sun, 24 Sep 1995 10:11:43 -0700 From: cpp@netcom.com (Robin Rowe) Message-ID: <199509241711.KAA12047@netcom22.netcom.com> Subject: istream weirdness Cc: cpp@netcom.com