Results 1 to 3 of 3

Thread: Convert a string (not char *) to a number

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516
    I've got a number from a textbox which is in the form of a string (from string.h, not a char * thing) and it has quite a few methods and stuff, and I was wondering which one converts the string to a, for example, float or long int ?

    I couldn't find anything on MSDN, and none of the methods say 'toNumber' or anything. Please, it is quite important since what use is a calculator project which doesn't bloody well know what numbers we're dealing with?

    Thanks,

    le MOI
    Courgettes.

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    You mean the STL string class?

    In that case, try atof/atoi with the c_str() member function of your string object.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516
    Originally posted by parksie
    You mean the STL string class?
    Errr. Probably?

    Thanks for the advice. I know about ato-x- and but I didn't know that c_str changed the string into something useful.

    Thanks again, Mikey boy,

    DJ Da Arse
    Courgettes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width