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. Converting CString to int in Visaul C++, please help.

Converting CString to int in Visaul C++, please help.

Scheduled Pinned Locked Moved C / C++ / MFC
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.
  • J Offline
    J Offline
    JavaTony
    wrote on last edited by
    #1

    Hi, I have two variables with types CString and int. int nWidth; CString strWidth; strWidth = "110"; How do I convert strWidth("110") to int type(110) so I can store it in nWidth? Please show me how to do this, thank you very much. :)

    M B L 3 Replies Last reply
    0
    • J JavaTony

      Hi, I have two variables with types CString and int. int nWidth; CString strWidth; strWidth = "110"; How do I convert strWidth("110") to int type(110) so I can store it in nWidth? Please show me how to do this, thank you very much. :)

      M Offline
      M Offline
      Matt Gullett
      wrote on last edited by
      #2

      use the atoi or atol functions. iWidth = atoi(strWidth);

      S 1 Reply Last reply
      0
      • J JavaTony

        Hi, I have two variables with types CString and int. int nWidth; CString strWidth; strWidth = "110"; How do I convert strWidth("110") to int type(110) so I can store it in nWidth? Please show me how to do this, thank you very much. :)

        B Offline
        B Offline
        Ben Burnett
        wrote on last edited by
        #3

        int nWidth = 110; CString strWidth; strWidth.Format ( "%d", nWidth ); // like the sprintf function -Ben --------- On the topic of code with no error handling -- It's not poor coding, it's "optimistic" ;)

        1 Reply Last reply
        0
        • J JavaTony

          Hi, I have two variables with types CString and int. int nWidth; CString strWidth; strWidth = "110"; How do I convert strWidth("110") to int type(110) so I can store it in nWidth? Please show me how to do this, thank you very much. :)

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Use function StrToInt this way int nWidth=StrToInt(strWidth); just one line of code and u got inr value.;) Gonna be 18 till I die

          C 1 Reply Last reply
          0
          • L Lost User

            Use function StrToInt this way int nWidth=StrToInt(strWidth); just one line of code and u got inr value.;) Gonna be 18 till I die

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #5

            Two problems. First, why use a non standard function when atoi works perfectly well, and second ( from MSDN) Windows NT/2000: Requires Windows 2000 (or Windows NT 4.0 with Internet Explorer 4.0 or later). Windows 95/98: Requires Windows 98 (or Windows 95 with Internet Explorer 4.0 or later). Sounds like a bad idea to me, unless you specifically do not target the platforms not supported, and even then I would personally prefer not to get into the habit of using something I may find unavailable to me down the track, for no good reason I can see. Christian #include "std_disclaimer.h" People who love sausage and respect the law should never watch either one being made. The things that come to those who wait are usually the things left by those who got there first.

            1 Reply Last reply
            0
            • M Matt Gullett

              use the atoi or atol functions. iWidth = atoi(strWidth);

              S Offline
              S Offline
              Stephen Kellett
              wrote on last edited by
              #6

              Or you could use strtod() and strtol(). strtol() is useful if you want to read a number that is not in base 10. For example to read hex numbers use strtol("0x12345678", NULL, 16) _tcstol() and _tcstod() are the macros for UNICODE/MBCS portability Stephen Kellett -- C++/Java/Win NT/Unix variants Memory leaks/corruptions/performance/system problems. UK based. Problems with RSI/WRULD? Contact me for advice.

              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