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. convert int to string

convert int to string

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorial
8 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.
  • S Offline
    S Offline
    sunita ramesh
    wrote on last edited by
    #1

    Hi all, Please any one tell me How to convert int to string ,string to int in vc++. thanks sunita

    S _ T O H 5 Replies Last reply
    0
    • S sunita ramesh

      Hi all, Please any one tell me How to convert int to string ,string to int in vc++. thanks sunita

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

      One way: ostringstream ss; ss << "The number is " << 42; string s = ss.str(); There are many ways. You didn't really explain the context properly so I assumed that by "string" you meant STL strings. Note that the above code assumes that you've included <string> and <sstream> and have put using namespace std; somewhere appropriate. Steve

      S 1 Reply Last reply
      0
      • S sunita ramesh

        Hi all, Please any one tell me How to convert int to string ,string to int in vc++. thanks sunita

        _ Offline
        _ Offline
        _AnsHUMAN_
        wrote on last edited by
        #3

        have a look at atoi() and itoa() For me CAR is Challenge, Achievement and Recognition. ;-) _AnShUmAn_

        1 Reply Last reply
        0
        • S Stephen Hewitt

          One way: ostringstream ss; ss << "The number is " << 42; string s = ss.str(); There are many ways. You didn't really explain the context properly so I assumed that by "string" you meant STL strings. Note that the above code assumes that you've included <string> and <sstream> and have put using namespace std; somewhere appropriate. Steve

          S Offline
          S Offline
          sunita ramesh
          wrote on last edited by
          #4

          hi, Thanks for ur reply. Actually i am storing picture number in int picno; I need to convert this picture number to string. can i able to convert? sunita

          S 1 Reply Last reply
          0
          • S sunita ramesh

            hi, Thanks for ur reply. Actually i am storing picture number in int picno; I need to convert this picture number to string. can i able to convert? sunita

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

            Almost exactly the same as the previous example: ostringstream ss; ss << picno; string s = ss.str(); Steve

            1 Reply Last reply
            0
            • S sunita ramesh

              Hi all, Please any one tell me How to convert int to string ,string to int in vc++. thanks sunita

              T Offline
              T Offline
              ThatsAlok
              wrote on last edited by
              #6

              sunita ramesh wrote:

              How to convert int to string ,string to int in vc++.

              CString::Format, wsprintf, _ttoi

              "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

              cheers, Alok Gupta VC Forum Q&A :- I/ IV

              1 Reply Last reply
              0
              • S sunita ramesh

                Hi all, Please any one tell me How to convert int to string ,string to int in vc++. thanks sunita

                O Offline
                O Offline
                Osama E Adly
                wrote on last edited by
                #7

                Using MFC: Convert int to string int x=12345; CString s; // s = "" (empty string) s.Format("%d", x); // s = "12345" as string Convert string to int int x=0; CString s="12345"; x = atoi(s); // x= 12345 as integer Osama E. Adly

                1 Reply Last reply
                0
                • S sunita ramesh

                  Hi all, Please any one tell me How to convert int to string ,string to int in vc++. thanks sunita

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

                  see http://msdn2.microsoft.com/en-us/library/yd5xkb5c.aspx[^]

                  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