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 from CString to integer? And Message Boxes

How to convert from CString to integer? And Message Boxes

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++tutoriallearning
4 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.
  • S Offline
    S Offline
    Star09
    wrote on last edited by
    #1

    How to convert from CString to integer? and Vise versa? Also, how can I display integer in message boxes? I keep getting errors, or are they always CString types? I'm just learning MFC, so bear with me,And sorry if my questions are stupid :sigh: --Star

    M H 2 Replies Last reply
    0
    • S Star09

      How to convert from CString to integer? and Vise versa? Also, how can I display integer in message boxes? I keep getting errors, or are they always CString types? I'm just learning MFC, so bear with me,And sorry if my questions are stupid :sigh: --Star

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      Here's a possible method for each direction...

      int i = 12345;
      CString str;

      // Convert integer i to string in str
      str.Format(_T("%d"), i);

      // Convert string in str to integer i
      // (_tstoi is generic text mapping for atoi()/_wtoi() RTL functions)
      i = _tstoi(str);

      For MessageBox, I'm not sure which one you are using - MFC, Windows API, etc. but you can format strings pretty much the same for all of them...

      int i = 12345;
      CString str;

      str.Format(_T("The value of i is %d"), i);
      int MessageBoxRet = AfxMessageBox(str, MB_ICONEXCLAMATION | MB_OK);

      "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

      S 1 Reply Last reply
      0
      • M Mark Salsbery

        Here's a possible method for each direction...

        int i = 12345;
        CString str;

        // Convert integer i to string in str
        str.Format(_T("%d"), i);

        // Convert string in str to integer i
        // (_tstoi is generic text mapping for atoi()/_wtoi() RTL functions)
        i = _tstoi(str);

        For MessageBox, I'm not sure which one you are using - MFC, Windows API, etc. but you can format strings pretty much the same for all of them...

        int i = 12345;
        CString str;

        str.Format(_T("The value of i is %d"), i);
        int MessageBoxRet = AfxMessageBox(str, MB_ICONEXCLAMATION | MB_OK);

        "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

        S Offline
        S Offline
        Star09
        wrote on last edited by
        #3

        Thank you! --Star

        1 Reply Last reply
        0
        • S Star09

          How to convert from CString to integer? and Vise versa? Also, how can I display integer in message boxes? I keep getting errors, or are they always CString types? I'm just learning MFC, so bear with me,And sorry if my questions are stupid :sigh: --Star

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

          And also you can use of wsprintf.


          WhiteSky


          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