Topic: algorithm to parse double


Author: remove.haberg@matematik.su.se (Hans Aberg)
Date: Fri, 26 Jul 2002 08:16:20 GMT
Raw View
In article <w_U%8.613$0m5.6883@eagle.america.net>, "Travis"
<oly_chierf_17@hotmail.com> wrote:

>not sure if this is the right newsgroup to send this to
>
>does the standard library have any algorithms for parsing double for strings
>(c-style or c++ style)?  i am trying to write my own, but sometimes it
>doesn't return the right number.
>
>also does anyone know if there good c++ API that i can download?

Convert the string to a stream using std::(i)stringstream in <sstream>,
and use the usual stream reading features. (Or strictly speaking, this
header will contain a std__basic_(i)stringstream and via a typedef in a
header iosfwd provide std::(i)stringstream.)

For simple parsing like this, you can hang out in the comp.c++ newsgroups.

For more complicated parsing, up to writing ones own language, one can use
lexer/parser generators like Flex/Bison <http://www.gnu.org>, which
currently are updated to support the current C++ standard. On this level,
the newsgroup comp.compilers and its FAQ published there regularly, is
useful.

  Hans Aberg      * Anti-spam: remove "remove." from email address.
                  * Email: Hans Aberg <remove.haberg@member.ams.org>
                  * Home Page: <http://www.matematik.su.se/~haberg/>
                  * AMS member listing: <http://www.ams.org/cml/>

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: "Travis" <oly_chierf_17@hotmail.com>
Date: Thu, 25 Jul 2002 16:52:09 GMT
Raw View
not sure if this is the right newsgroup to send this to

does the standard library have any algorithms for parsing double for strings
(c-style or c++ style)?  i am trying to write my own, but sometimes it
doesn't return the right number.

also does anyone know if there good c++ API that i can download?


======================================= MODERATOR'S COMMENT:

I'm approving this because you're asking about the contents
of the Standard Library.  If you want to ask about nonstandard
C++ APIs that you can download, you'd be better off with a
different newsgroup.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: "Renato Mancuso" <mancuso@ebi.ac.uk>
Date: Thu, 25 Jul 2002 20:13:02 GMT
Raw View
Hi Travis,

if you want to see how it is done the simplest is probably to look for the sources of the strtod() function. Or alternatively you
could try to get a copy of P.J.Plauger book on the standard C library, which has the additional benefits of having comments.

Cheers

Renato

"Travis" <oly_chierf_17@hotmail.com> wrote in message news:w_U%8.613$0m5.6883@eagle.america.net...
not sure if this is the right newsgroup to send this to

does the standard library have any algorithms for parsing double for strings
(c-style or c++ style)?  i am trying to write my own, but sometimes it
doesn't return the right number.




---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: "Ken Alverson" <Ken@Alverson.net>
Date: 25 Jul 2002 21:05:04 GMT
Raw View
"Travis" <oly_chierf_17@hotmail.com> wrote in message
news:w_U%8.613$0m5.6883@eagle.america.net...
> not sure if this is the right newsgroup to send this to
>
> does the standard library have any algorithms for parsing double for
strings
> (c-style or c++ style)?  i am trying to write my own, but sometimes it
> doesn't return the right number.

std::istringstream i(inputString);
double d;
i >> d;

Ken


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]