what is the difference between sscanf and atof in cast cstring into float?
C / C++ / MFC
3
Posts
3
Posters
0
Views
1
Watching
-
when i need cast cstring into float , i always use sscanf(mystr,"%f",ftype)//float ftype fype=atof(mystr) but which is better ,what is the difference between them?
atof()
will be faster because it does not have to parse a format string likesscanf()
does.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
-
when i need cast cstring into float , i always use sscanf(mystr,"%f",ftype)//float ftype fype=atof(mystr) but which is better ,what is the difference between them?
atof is faster and smaller since it does not have the overhead of a format string scanner - I would think that sscanf calls atof when it finds the %f in a format string. FYI, you are not doing a cast, you are doing a conversion. Steve