• Advertisement
Sign in to follow this  

stdlib.h with atof

This topic is 4523 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

hello, i'm in the middle of creating my windows killing desktop enviroment, now right now i am creating the scripting language for the maps. however, when going through the data and trying to gather points via atof i get bad data back. i am using strings along with the c_str() member functions. I was wondering if anyone out there has had problems themselves with strings with the atof functions.

Share this post


Link to post
Share on other sites
Advertisement
so you're using C++ strings with old conversion functions? Really I don't even know why people use atoi or atof anymore.

Use strstream(or stringstream) to create a lexcial cast function


template<typename R, typename T> // R is the return type
R LexicalCast(T const& Type) {
R Ret;
strstream StrStrm;
StrStrm << Type;
StrStrm >> Ret;
return Ret;}




or use the boost version.

Edit: and it's <cstdlib> not <stdlib.h>

Share this post


Link to post
Share on other sites
Quote:
Original post by hogosha
im doing this on a linux machine, it's stdlib for me.

What does using linux have to do with not using the standard C++ library? And if you can't use it, why are you using string?

Share this post


Link to post
Share on other sites
Indeed. Anywhere you can use std::string, you can use std::stringstream (not 'strstream'; and the necessary header is <sstream>).

Share this post


Link to post
Share on other sites
Quote:
Original post by Scet
Really I don't even know why people use atoi or atof anymore.


speed

Share this post


Link to post
Share on other sites
Quote:
Original post by Brother Bob
Quote:
Original post by hogosha
im doing this on a linux machine, it's stdlib for me.

What does using linux have to do with not using the standard C++ library? And if you can't use it, why are you using string?


<stdlib.h>

c standard library header file - usually available ( i use gcc/g++ so i dont know if this is always the case )

<cstdlib>

c++ version of above - available with c++ compiler

difference - cstdlib finctions are in namespace std (like all standard library)

linux makes no difference...

Share this post


Link to post
Share on other sites
i'm using gcc 3.4.4 and i get compile errors when trying to include cstdlib. anyhow, i was just more wondering if anyone had ran into a problem doing an string's constant string output to atof. i get numbers that have nothing to do with it.

Share this post


Link to post
Share on other sites
i took some spaces off the ends of the final floating point for each coordinate, and that seem to have fixed it. now i have to figure out where i read cleaned the data improperly, cuz i'm going through the data in steps.

1. read in all the data.
2. take the read in data and seperate it until finding ending line terminator e.g. ";" as well as doing any data cleaning for the next step.
3. take parsed data and read it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement