converting strings to numbers
how would i convert a string to a float or an integer?
thx in advance
The wymsical wyvern
Off the top my head I think that strtol() converts strings to long ints.
http://users.50megs.com/crazyvasey/
http://users.50megs.com/crazyvasey/
atoi() - string to integer
atof() - string to float
atol() - string to long
When programming in Windows, atoi and atol are both the same!
-------------------------------
That's just my 200 bucks' worth!
..-=gLaDiAtOr=-..
atof() - string to float
atol() - string to long
When programming in Windows, atoi and atol are both the same!
-------------------------------
That's just my 200 bucks' worth!
..-=gLaDiAtOr=-..
Are you asking about the STL string class? or character arrays?
-Eck
-Eck
EckTech Games - Games and Unity Assets I'm working on
Still Flying - My GameDev journal
The Shilwulf Dynasty - Campaign notes for my Rogue Trader RPG
August 18, 2000 05:35 PM
I''d use the atoi(), atol(), atof() as posted above but there is another solution if you want to be Mr. C++ guy (I''m doing this from memory so this may not be perfect):
#include
#include
std::string str( "400" );
std::istringstream ss( str );
int i;
ss >> i;
#include
#include
std::string str( "400" );
std::istringstream ss( str );
int i;
ss >> i;
Somebody had a similar question before and some dude posted about using sprintf to do it... I''m not a C guy so I don''t remember what he did... but that seemed the easiest..
40
www.databyss.com
www.omlettesoft.com
"Don''t meddle in the affairs of wizards, for they are subtle and quick to anger."
40
www.databyss.com
www.omlettesoft.com
"Don''t meddle in the affairs of wizards, for they are subtle and quick to anger."
-40
Here''s that post that I was talking about:
http://www.gamedev.net/community/forums/topic.asp?topic_id=22696&forum_id=11&Topic_Title=Help+with+itoa+in+c%2B%2B&forum_title=General+and+Game+Programming+Discussion&M=False&S=True
40
www.databyss.com
www.omlettesoft.com
"Don''t meddle in the affairs of wizards, for they are subtle and quick to anger."
http://www.gamedev.net/community/forums/topic.asp?topic_id=22696&forum_id=11&Topic_Title=Help+with+itoa+in+c%2B%2B&forum_title=General+and+Game+Programming+Discussion&M=False&S=True
40
www.databyss.com
www.omlettesoft.com
"Don''t meddle in the affairs of wizards, for they are subtle and quick to anger."
-40
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement