Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

SarsDP

string to float

This topic is 5556 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
quote:
Original post by Mishkin
In c++, use atof() and pass it a const char *

No ... in C, use atof(). In C++, use a stringstream.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Assuming you are using C. Try atof()

Share this post


Link to post
Share on other sites
Just for the record im using C++, and thanks for the quick replies but i have one more question now. What header is stringstream in?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I would''ve done it using atof, but the man page said it was deprecated and to use strtod.


char *s = ...;
char *end;
double d;

d = strtod(s, &end);

if (s == c) { /* no conversion */ }
else if (errno == ERANGE) { /* overflow/underflow */ }
else { /* d is valid */ }


This assumes errno isn''t set before invoking this code section.

Share this post


Link to post
Share on other sites
I included sstream and i get this error
error C2065: 'stringstream' : undeclared identifier


[edited by - SarsDP on May 1, 2003 11:16:31 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!