Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Conversion, string to int

Conversion, string to int

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
6 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • _ Offline
    _ Offline
    __Cerb
    wrote on last edited by
    #1

    Anyone knows how to? Thanks ~Mike

    J M S 3 Replies Last reply
    0
    • _ __Cerb

      Anyone knows how to? Thanks ~Mike

      J Offline
      J Offline
      JWood
      wrote on last edited by
      #2

      Are you looking for the function atoi? this is an old but much maligned function. If it is you you only have to say "Thanks masked man - you have saved my life" go cobol young man - go cobol


      My neighbours think I am crazy - but they don't know that I have a trampoline. All they see my head bobbing up and down over the fence every five seconds

      1 Reply Last reply
      0
      • _ __Cerb

        Anyone knows how to? Thanks ~Mike

        M Offline
        M Offline
        Michael Dunn
        wrote on last edited by
        #3

        See the FAQ 6.3: How can I change a number into its string representation, or vice versa?[^] --Mike-- Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber You cannot stop me with paramecium alone!

        B 1 Reply Last reply
        0
        • M Michael Dunn

          See the FAQ 6.3: How can I change a number into its string representation, or vice versa?[^] --Mike-- Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber You cannot stop me with paramecium alone!

          B Offline
          B Offline
          BaldwinMartin
          wrote on last edited by
          #4

          cobol just told you, how to convert from str to int so you have that right? int x = atoi("123456"); now to change that back to an int? ok right out of MSDN char *string, *stopstring; double x; long l; // or int int base; unsigned long ul; string = "3.1415926This stopped it"; x = strtod( string, &stopstring ); printf( "string = %s\n", string ); printf(" strtod = %f\n", x ); printf(" Stopped scan at: %s\n\n", stopstring ); string = "-10110134932This stopped it"; l = strtol( string, &stopstring, 10 ); printf( "string = %s", string ); printf(" strtol = %ld", l ); printf(" Stopped scan at: %s", stopstring ); string = "10110134932"; Best Wishes and Happy Holiday's, ez_way

          1 Reply Last reply
          0
          • _ __Cerb

            Anyone knows how to? Thanks ~Mike

            S Offline
            S Offline
            Scozturk
            wrote on last edited by
            #5

            You can use the atoi() function if it a CString. If it is LPTSTR or some other string stuff I prefer writing them on an invisible static text box and retrieving them as an interger. I hope this helps! Well... I am a beginner ...

            I 1 Reply Last reply
            0
            • S Scozturk

              You can use the atoi() function if it a CString. If it is LPTSTR or some other string stuff I prefer writing them on an invisible static text box and retrieving them as an interger. I hope this helps! Well... I am a beginner ...

              I Offline
              I Offline
              Ian Darling
              wrote on last edited by
              #6

              Scolinks wrote: You can use the atoi() function if it a CString. If it is LPTSTR or some other string stuff I prefer writing them on an invisible static text box and retrieving them as an interger. I hope this helps! Well... I am a beginner ... Yuck! (the static text box thing) But forgivable for a beginner (just :-)) I think it's time you were introduced to the boost library, and in particular the lexical_cast<> template. Also note that an LPTSTR (long pointer to a TCHAR string) can be one of two things - a pointer to a char array (char *), or a pointer to a wide-char string (wchar_t *, which is a full type in VC.NET, and a typedef for short in VC6) The T bit is the TCHAR thing mentioned earlier - TCHAR means char or wchar_t, depending on if you are building an ANSI/ASCII version of your code, or a UNICODE one. I would suggest that you look up the relevant functions for conversions, which can handle unicode or ansi strings as necessary (eg, _tcstoul for converting a LPTSTR to an unsigned long). HTH -- Ian Darling "The moral of the story is that with a contrived example, you can prove anything." - Joel Spolsky

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups