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. Managed C++/CLI
  4. problem with converting CString to int

problem with converting CString to int

Scheduled Pinned Locked Moved Managed C++/CLI
help
4 Posts 4 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.
  • S Offline
    S Offline
    singersinger
    wrote on last edited by
    #1

    now i have a CString variable contain an integer value i wanna convert the CString to int so i used atoi() function CString strNumber = "00123" int nNumber = atoi(strNumber); then nNumber will contain (123)and it ignore the Zeros so what if i need these Zeros, what should i do also if i wrote int x = 0110; x will result into (72) could anybody explain that thnx 4 ur time and concern

    E L T 3 Replies Last reply
    0
    • S singersinger

      now i have a CString variable contain an integer value i wanna convert the CString to int so i used atoi() function CString strNumber = "00123" int nNumber = atoi(strNumber); then nNumber will contain (123)and it ignore the Zeros so what if i need these Zeros, what should i do also if i wrote int x = 0110; x will result into (72) could anybody explain that thnx 4 ur time and concern

      E Offline
      E Offline
      Epi
      wrote on last edited by
      #2

      hello, In a integer you can't keep the zeros, so if you want the zeros at the left you have to use string and so on, About the second problem, if you put 0 at the left, you are using octal system so, 0110 = 0*8^3+1*8^2+1*8+0 = 72 Regards -- modified at 10:03 Wednesday 11th October, 2006

      1 Reply Last reply
      0
      • S singersinger

        now i have a CString variable contain an integer value i wanna convert the CString to int so i used atoi() function CString strNumber = "00123" int nNumber = atoi(strNumber); then nNumber will contain (123)and it ignore the Zeros so what if i need these Zeros, what should i do also if i wrote int x = 0110; x will result into (72) could anybody explain that thnx 4 ur time and concern

        L Offline
        L Offline
        led mike
        wrote on last edited by
        #3

        singersinger wrote:

        so what if i need these Zeros, what should i do

        padding zeros is a display formatting operation and has nothing to do with the value of the intrinsice numeric type (int, long, etc.)

        singersinger wrote:

        x will result into (72)

        if you want x = 110 write: int x = 110; otherwise the leading zero is interpreted by the compiler to mean "octal" just as leading 0x means hexadecimal.

        led mike

        1 Reply Last reply
        0
        • S singersinger

          now i have a CString variable contain an integer value i wanna convert the CString to int so i used atoi() function CString strNumber = "00123" int nNumber = atoi(strNumber); then nNumber will contain (123)and it ignore the Zeros so what if i need these Zeros, what should i do also if i wrote int x = 0110; x will result into (72) could anybody explain that thnx 4 ur time and concern

          T Offline
          T Offline
          tydok
          wrote on last edited by
          #4

          note: int x; x= 0110; //oct value 0"number", base 8 x= 0x110; //hex value 0x"number", base 16 x= 110; //dec value, base 10 so a 0110(base 8) number is 72(base 10) * use Windows calculator to check the above values you can NOT keep the zeros if you use a "int" type

          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