Hello all,
#include <sstream>
#include <iostream>
int main()
{
std::istringstream iss("6.5e");
double size;
char fit;
iss >size >fit;
std::cout << "size(" << size << "), fit(" << fit << ")" << std::endl;
}
This program doesn't extract the elements okay (apparent garbage
output) but if the input stream is 6.5d it does. I figure this is
because the extraction operator thinks it's going to have a number
like 6.5e+12??? Is there a way I can turn this feature off and make it
extract 6.5 and d separately?
Regards,
Pete 5 2078
On Tue, 09 Sep 2008 12:32:33 +0200, Alf P. Steinbach wrote:
Not that I know: it amounts to defining new syntax for double literal.
It might be possible to fool stream into thinking 'e' is separator, but
that would be very ugly hack, and probably not well-defined by standard.
I'd just use a loop to copy characters while digit or radix point; much
less work than finding out if hack works and whether supported by
standard. :-)
Hi, just a bit of playing with the simple code,
double a = 4.3e;
is not a valid definition because there should be an exponent after the
'e', but is there sth else defined for istringstream class, because it
can extract 6.5e even if it is not a valid expression outside the double
quotes, trying a string such as 6.5e is extracted as 6.5 only and 6.5ee
as 6.5 and e...
On Sep 9, 5:53 pm, utab <umut.ta...@gmail.comwrote:
On Tue, 09 Sep 2008 12:32:33 +0200, Alf P. Steinbach wrote:
Not that I know: it amounts to defining new syntax for
double literal.
It might be possible to fool stream into thinking 'e' is
separator, but that would be very ugly hack, and probably
not well-defined by standard.
I'd just use a loop to copy characters while digit or radix
point; much less work than finding out if hack works and
whether supported by standard. :-)
Hi, just a bit of playing with the simple code,
double a = 4.3e;
is not a valid definition because there should be an exponent
after the 'e', but is there sth else defined for istringstream
class, because it can extract 6.5e even if it is not a valid
expression outside the double quotes, trying a string such as
6.5e is extracted as 6.5 only and 6.5ee as 6.5 and e...
I don't think that this is right, although interpreting the
standard literally... It looks like there's an error in the
standard. This is certainly not what one would want or expect;
a stream should never silently drop a non white space character.
(Most implementations do the right thing, and set fail in this
case.)
--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
On Sep 10, 9:59 am, James Kanze <james.ka...@gmail.comwrote:
On Sep 9, 5:53 pm, utab <umut.ta...@gmail.comwrote:
On Tue, 09 Sep 2008 12:32:33 +0200, Alf P. Steinbach wrote:
Not that I know: it amounts to defining new syntax for
double literal.
It might be possible to fool stream into thinking 'e' is
separator, but that would be very ugly hack, and probably
not well-defined by standard.
I'd just use a loop to copy characters while digit or radix
point; much less work than finding out if hack works and
whether supported by standard. :-)
Hi, just a bit of playing with the simple code,
double a = 4.3e;
is not a valid definition because there should be an exponent
after the 'e', but is there sth else defined for istringstream
class, because it can extract 6.5e even if it is not a valid
expression outside the double quotes, trying a string such as
6.5e is extracted as 6.5 only and 6.5ee as 6.5 and e...
I don't think that this is right, although interpreting the
standard literally... It looks like there's an error in the
standard. This is certainly not what one would want or expect;
a stream should never silently drop a non white space character.
(Most implementations do the right thing, and set fail in this
case.)
Just a follow-up: there is an active DR on this: DR23 (one of
the oldest around). It is apparently still under review. (The
actual DR concerns behavior in case of overflow, but the
proposed changes in wording would require reading something like
"1.23ex" into a floating point to set failbit and store 0.0 in
the result.)
--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
On Wed, 10 Sep 2008 00:59:15 -0700, James Kanze wrote:
>
I don't think that this is right, although interpreting the standard
literally... It looks like there's an error in the standard. This is
certainly not what one would want or expect; a stream should never
silently drop a non white space character. (Most implementations do the
right thing, and set fail in this case.)
It was also strange for me, but I could not get the conclusion from your
explanation, I got the previous results with g++, intel compiler reads
another character into(unrecognizable on cout output, but there is sth)
'fit()' which is given in the original code.
Thanks
On Sep 10, 7:18 pm, utab <umut.ta...@gmail.comwrote:
On Wed, 10 Sep 2008 00:59:15 -0700, James Kanze wrote:
I don't think that this is right, although interpreting the
standard literally... It looks like there's an error in the
standard. This is certainly not what one would want or
expect; a stream should never silently drop a non white
space character. (Most implementations do the right thing,
and set fail in this case.)
It was also strange for me, but I could not get the conclusion
from your explanation, I got the previous results with g++,
intel compiler reads another character into(unrecognizable on
cout output, but there is sth) 'fit()' which is given in the
original code.
See my follow-up to my own posting. This is clearly an error in
the standard; g++ simply implements exactly what was written,
even though it was obviously wrong, and inconsistent with
existing practice. All of the other compilers I have access to
(VC++, Sun CC, both with the RogueWave library and with STLPort)
behave "correctly"; that is, they do what one would expect, and
what the proposed resolution to the DR requires, and set
failbit.
--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: blix |
last post by:
When I output my char to a stream and it has a value of 11, it writes a ^B
(vertical tab). This is understandable. When I attempt to stream it back
into a char variable, it skips it because a tab...
|
by: Hendrik Schober |
last post by:
Hi,
I have a 'std::istream' and need to read
its whole contents into a string. How can
I do this?
TIA;
Schobi
|
by: Sonny |
last post by:
Hi experts,
I am writing a small code to read input from a file, for example my
input file is:
X Y Z
26.0 28.0 0.0
32.0 8.0 0.0
My code is:...
|
by: Adam H. Peterson |
last post by:
I would like to make a stream or streambuf that tracks the number of
lines that have been read and stuff like that (so, for example, when I
get an error message, I can ask the stream for the line...
|
by: yeutim |
last post by:
I can't find anything wrong this with this class. Especially,
Overloading Stream-Extraction Operator (in blue). Any one know what
do I need to fix this problem please reply. Thank you for your...
|
by: sherifffruitfly |
last post by:
Hi,
I've a got a little (exercise) program that reads data from a file and
puts it into struct members. I run into trouble when one of the data
pieces is comprised of several words (eg "john...
|
by: B. Williams |
last post by:
I have an assignment for school to Overload the operators << and >and I
have written the code, but I have a problem with the insertion string
function. I can't get it to recognize the second of...
|
by: beatTheDevil |
last post by:
Hello all,
I have a question that concerns how C++ input streams (istream, ifstream, istringstream, etc.) behave using the extraction (>>) operator when at the end of a stream's contents.
For...
|
by: john |
last post by:
I am reading TC++PL3 and in "21.3.3 Stream State", 4 member functions
returning bool are mentioned:
template <class Ch, class Tr= char_traits<Ch
class basic_ios: public ios_base {
public:
//...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| |