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 type cast from CString to int [modified]

how to type cast from CString to int [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
tutorial
8 Posts 7 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.
  • Y Offline
    Y Offline
    yogendra kaushik
    wrote on last edited by
    #1

    please any ont tell me how to type cast from CString to int actually i receive the value from user and the value is int type but i used its datatype CString now for futhure operation i want to typecast it to int . so plz tell me how i convert it. Please mail me -- modified at 2:04 Thursday 15th June, 2006

    L A N H J 5 Replies Last reply
    0
    • Y yogendra kaushik

      please any ont tell me how to type cast from CString to int actually i receive the value from user and the value is int type but i used its datatype CString now for futhure operation i want to typecast it to int . so plz tell me how i convert it. Please mail me -- modified at 2:04 Thursday 15th June, 2006

      L Offline
      L Offline
      Laxman Auti
      wrote on last edited by
      #2

      yogendra kaushik wrote:

      please any ont tell me how to typa cast from CString to int i get the CString type value from user now i want to convert it in to int for any use so plz tell me how i convert it.

      here is one way int i=atoi(str.GetBuffer()); str.ReleaseBuffer(); Knock out 't' from can't, You can if you think you can :cool:

      S 1 Reply Last reply
      0
      • Y yogendra kaushik

        please any ont tell me how to type cast from CString to int actually i receive the value from user and the value is int type but i used its datatype CString now for futhure operation i want to typecast it to int . so plz tell me how i convert it. Please mail me -- modified at 2:04 Thursday 15th June, 2006

        A Offline
        A Offline
        Amar Sutar
        wrote on last edited by
        #3

        Use _ttoi() function Amar:)

        1 Reply Last reply
        0
        • Y yogendra kaushik

          please any ont tell me how to type cast from CString to int actually i receive the value from user and the value is int type but i used its datatype CString now for futhure operation i want to typecast it to int . so plz tell me how i convert it. Please mail me -- modified at 2:04 Thursday 15th June, 2006

          N Offline
          N Offline
          NiceNaidu fo
          wrote on last edited by
          #4

          Try this way. CString strInteger(_T("302")); int iValue = _ttoi(strInteger); i value will be 302 Appu.. "If you judge people, you have no time to love them."

          1 Reply Last reply
          0
          • Y yogendra kaushik

            please any ont tell me how to type cast from CString to int actually i receive the value from user and the value is int type but i used its datatype CString now for futhure operation i want to typecast it to int . so plz tell me how i convert it. Please mail me -- modified at 2:04 Thursday 15th June, 2006

            H Offline
            H Offline
            Hamid Taebi
            wrote on last edited by
            #5

            of course you find your answer in atoi and... but see this link i think its goodConverting numeric types to strings and strings to numeric types[^]_**


            **_

            whitesky


            1 Reply Last reply
            0
            • L Laxman Auti

              yogendra kaushik wrote:

              please any ont tell me how to typa cast from CString to int i get the CString type value from user now i want to convert it in to int for any use so plz tell me how i convert it.

              here is one way int i=atoi(str.GetBuffer()); str.ReleaseBuffer(); Knock out 't' from can't, You can if you think you can :cool:

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

              Calling GetBuffer and ReleaseBuffer is completely unnecessary. The following will work: CString FName = "10"; int n = atoi(FName); It works because CString has an operator LPCTSTR. Steve

              L 1 Reply Last reply
              0
              • S Stephen Hewitt

                Calling GetBuffer and ReleaseBuffer is completely unnecessary. The following will work: CString FName = "10"; int n = atoi(FName); It works because CString has an operator LPCTSTR. Steve

                L Offline
                L Offline
                Laxman Auti
                wrote on last edited by
                #7

                Stephen Hewitt wrote:

                Calling GetBuffer and ReleaseBuffer is completely unnecessary

                Ohh... GetBuffer and ReleaseBuffer is mostly used where you want to modify data of the CString instead of Format. Knock out 't' from can't, You can if you think you can :cool:

                1 Reply Last reply
                0
                • Y yogendra kaushik

                  please any ont tell me how to type cast from CString to int actually i receive the value from user and the value is int type but i used its datatype CString now for futhure operation i want to typecast it to int . so plz tell me how i convert it. Please mail me -- modified at 2:04 Thursday 15th June, 2006

                  J Offline
                  J Offline
                  John R Shaw
                  wrote on last edited by
                  #8

                  You have recieved several answers to your question and they all show you how to convert a string to integer. Take note that this is not type casting, it is conversion from one form to another. This is important because you could type cast a string to an integer value but the value would not be the value entered in the string. It would take the individule byes and assume they are parts of the final number you are seeking. char str = "AB"; // 'A' = 0x41, 'B' = 0x42 short n = (short*)(str); // n = 0x4241 = 16961 If you are wondering about the reversal of the numbers durring the type casting, then you need to go look up big endian and little endian on the Web. INTP "Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra

                  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