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. How to convert CString to int

How to convert CString to int

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
7 Posts 5 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.
  • M Offline
    M Offline
    mr2003
    wrote on last edited by
    #1

    Hi, I would like to know how to convert CString to int??? Thanks Ehsan Behboudi

    S M 3 Replies Last reply
    0
    • M mr2003

      Hi, I would like to know how to convert CString to int??? Thanks Ehsan Behboudi

      S Offline
      S Offline
      Steven Hicks n 1
      wrote on last edited by
      #2

      inVariable=_ttoi(CStringVariable) or even better sscanf(CStringVariable, "%d", intVarible -Steven Hicks

      CPA

      CodeProjectAddict

      Actual Linux Penguins were harmed in the creation of this message.

      More tutorials: Ltpb.8m.com: Tutorials |404Browser.com (Download Link)

      1 Reply Last reply
      0
      • M mr2003

        Hi, I would like to know how to convert CString to int??? Thanks Ehsan Behboudi

        S Offline
        S Offline
        Steven Hicks n 1
        wrote on last edited by
        #3

        inVariable=_ttoi(CStringVariable) or even better sscanf(CStringVariable, "%d", intVarible); -Steven Hicks

        CPA

        CodeProjectAddict

        Actual Linux Penguins were harmed in the creation of this message.

        More tutorials: Ltpb.8m.com: Tutorials |404Browser.com (Download Link)

        1 Reply Last reply
        0
        • M mr2003

          Hi, I would like to know how to convert CString to int??? Thanks Ehsan Behboudi

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

          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 | 1ClickPicGrabber New v2.0! | RightClick-Encrypt "Linux is good. It can do no wrong. It is open source so must be right. It has penguins. I want to eat your brain."   -- Paul Watson, Linux Zombie

          J 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 | 1ClickPicGrabber New v2.0! | RightClick-Encrypt "Linux is good. It can do no wrong. It is open source so must be right. It has penguins. I want to eat your brain."   -- Paul Watson, Linux Zombie

            J Offline
            J Offline
            Jagadeesh VN
            wrote on last edited by
            #5

            Hi Mike, I presume, the code snippet below can convert a string to long, and is the most fastest method. ConvertStringToLong( char* szFieldValue,long &lValue ) { //Validate the string :) int nLength = sizeof(unsigned long); char szBuffer1[ 8 ]; char szBuffer[ 8 ]; szBuffer1[nLength] = '\0'; memset( szBuffer1,0,nLength ); szBuffer[nLength] = '\0'; memset( szBuffer,0,nLength ); memcpy((void*) (szBuffer1 + nLength - stringLength ),szFieldValue,stringLength ); for( int i=0;i

            T 1 Reply Last reply
            0
            • J Jagadeesh VN

              Hi Mike, I presume, the code snippet below can convert a string to long, and is the most fastest method. ConvertStringToLong( char* szFieldValue,long &lValue ) { //Validate the string :) int nLength = sizeof(unsigned long); char szBuffer1[ 8 ]; char szBuffer[ 8 ]; szBuffer1[nLength] = '\0'; memset( szBuffer1,0,nLength ); szBuffer[nLength] = '\0'; memset( szBuffer,0,nLength ); memcpy((void*) (szBuffer1 + nLength - stringLength ),szFieldValue,stringLength ); for( int i=0;i

              T Offline
              T Offline
              Tim Smith
              wrote on last edited by
              #6

              Um, there must be a ton of stuff missing from this routine because it won't compile and I can see a few ways I can get it to crash. Tim Smith I'm going to patent thought. I have yet to see any prior art.

              J 1 Reply Last reply
              0
              • T Tim Smith

                Um, there must be a ton of stuff missing from this routine because it won't compile and I can see a few ways I can get it to crash. Tim Smith I'm going to patent thought. I have yet to see any prior art.

                J Offline
                J Offline
                Jagadeesh VN
                wrote on last edited by
                #7

                I know Tim, You can crash it very easily, B'coz I haven't freed the memory, and there are a couple of other mistakes as well. But my intention was only to, break the conventional approach on converting a string to int. Its just stupid to think that, someone else will do all the jobs for U. You may have to correct the mistakes, if thr are any. "A robust program is resistant to errors -- it either works correctly, or it does not work at all; whereas a fault tolerant program must actually recover from errors."

                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