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. CString 2 integer and reverse

CString 2 integer and reverse

Scheduled Pinned Locked Moved C / C++ / MFC
question
6 Posts 3 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
    macmac38
    wrote on last edited by
    #1

    Hello, i have a text file where i store a number. When i read the value in my szBuffer(CString) i like to cast this to an integer because i want to increment this value. After the incrementation i like to write the value back into the file. So cast from int to CString(szBuffer) Any ideas, code? Thanks, Mark

    J 1 Reply Last reply
    0
    • M macmac38

      Hello, i have a text file where i store a number. When i read the value in my szBuffer(CString) i like to cast this to an integer because i want to increment this value. After the incrementation i like to write the value back into the file. So cast from int to CString(szBuffer) Any ideas, code? Thanks, Mark

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

      try this: iInteger=atoi(LPCTSTR(csCString)); iInteger++; csCString.Format("%d",iInteger); this should do it! greets, Jason

      M J 2 Replies Last reply
      0
      • J jason99

        try this: iInteger=atoi(LPCTSTR(csCString)); iInteger++; csCString.Format("%d",iInteger); this should do it! greets, Jason

        M Offline
        M Offline
        macmac38
        wrote on last edited by
        #3

        yeah, works great. And how is the function to cast int to CString??;) Thanks, Mark

        R 1 Reply Last reply
        0
        • M macmac38

          yeah, works great. And how is the function to cast int to CString??;) Thanks, Mark

          R Offline
          R Offline
          roel_
          wrote on last edited by
          #4

          C style: char buf[10]; int number = 5; sprintf(buf, "%d", number); CString bleh = buf; STL style: #include std::ostringstream str; int number = 5; str << number; CString bleh = str.str().c_str(); MFC style: CString bleh; int number = 5; bleh.Format("%d", number); Boost style (www.boost.org): #include int number = 5; std::string str = boost::lexical_cast(number); CString bleh = str.c_str();

          M 1 Reply Last reply
          0
          • R roel_

            C style: char buf[10]; int number = 5; sprintf(buf, "%d", number); CString bleh = buf; STL style: #include std::ostringstream str; int number = 5; str << number; CString bleh = str.str().c_str(); MFC style: CString bleh; int number = 5; bleh.Format("%d", number); Boost style (www.boost.org): #include int number = 5; std::string str = boost::lexical_cast(number); CString bleh = str.c_str();

            M Offline
            M Offline
            macmac38
            wrote on last edited by
            #5

            Oh yes ok. I am still sleeping... Thanks, Mark

            1 Reply Last reply
            0
            • J jason99

              try this: iInteger=atoi(LPCTSTR(csCString)); iInteger++; csCString.Format("%d",iInteger); this should do it! greets, Jason

              J Offline
              J Offline
              jason99
              wrote on last edited by
              #6

              As i already wrote: if you are using the MFC CString class, simply use CString::Format(); else use sprintf(); examples: csCString.Format("%d",iInteger); or sprintf(cBuffer,"%d",iInteger); (where cBuffer is of type char*) greets, jason

              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