Advertisement

converting char array (string) to a number?

Started by February 19, 2003 07:53 PM
4 comments, last by TwistedMatrix 21 years, 9 months ago
what function does this? I have seen it before but i cant find it.
- Twisted Matrix
the string must be a string of numbers, correct?
This post will self-destruct in 5 seconds...Actually, it's just Benjamin Bunny doing his thing.
Advertisement
nvm its atoi();
- Twisted Matrix
atoi()
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Formats______________________________________________________________________________________
atoi(), holy holy atoi(). We praise thee...atoi()...hoooommmm
hooooommm......hooooom....atoiiiiiii...hoooooommmm
This post will self-destruct in 5 seconds...Actually, it's just Benjamin Bunny doing his thing.
The STL provides a very clean solution:


        #include <iostream> #include <sstream>  double StringToNumber(std::string str){	std::stringstream ss;	ss << str; 	double result;	ss >> result; 	return result;} int main(){	// ... 	double numberFromString = StringToNumber("12345.6");	char tResults[5] = /* stuff */;	numberFromString = StringToNumber(tResults); 	// ... 	return 0;}        

[ Google || Start Here || ACCU || MSDN || STL || GameCoding || BarrysWorld || E-Mail Me ]

[edited by - Lektrix on February 20, 2003 5:58:13 AM]
[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || CUJ || MSVC++ Library Fixes || BarrysWorld || [email=lektrix@barrysworld.com]E-Mail Me[/email] ]

This topic is closed to new replies.

Advertisement