stdlib.h with atof
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.
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
or use the boost version.
Edit: and it's <cstdlib> not <stdlib.h>
Use strstream(or stringstream) to create a lexcial cast function
template<typename R, typename T> // R is the return typeR 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>
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?
Indeed. Anywhere you can use std::string, you can use std::stringstream (not 'strstream'; and the necessary header is <sstream>).
Quote:Original post by Brother BobQuote: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...
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.
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement