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 in c++

convert int to string in c++

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++question
8 Posts 5 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
    monageasmear
    wrote on last edited by
    #1

    sorry im new to c++i no this is a simple problem but help would be greatly appreciated convert an int to a string? cheers

    P S T 3 Replies Last reply
    0
    • M monageasmear

      sorry im new to c++i no this is a simple problem but help would be greatly appreciated convert an int to a string? cheers

      P Offline
      P Offline
      PJ Arends
      wrote on last edited by
      #2

      _itoa CString::Format sprintf strstream class etc Many different ways


      "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!


      Honoured as one of The Most Helpful Members of 2004

      M 1 Reply Last reply
      0
      • P PJ Arends

        _itoa CString::Format sprintf strstream class etc Many different ways


        "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!


        Honoured as one of The Most Helpful Members of 2004

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

        sorry can you please post the code example int fig = 2; string string1; thanks

        M P T 3 Replies Last reply
        0
        • M monageasmear

          sorry can you please post the code example int fig = 2; string string1; thanks

          M Offline
          M Offline
          mark novak
          wrote on last edited by
          #4

          try using string streams from sstream.h int fig = 2; std::string string1; std::ostringstream oss; oss << fig; string1 = oss.str();

          1 Reply Last reply
          0
          • M monageasmear

            sorry can you please post the code example int fig = 2; string string1; thanks

            P Offline
            P Offline
            PJ Arends
            wrote on last edited by
            #5

            int fig = 2; string string1; strstream stream; stream << fig << ends; string1 = stream.str();


            "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!


            Honoured as one of The Most Helpful Members of 2004

            1 Reply Last reply
            0
            • M monageasmear

              sorry im new to c++i no this is a simple problem but help would be greatly appreciated convert an int to a string? cheers

              S Offline
              S Offline
              samira forooghi
              wrote on last edited by
              #6

              CString str; int i=5; str.Format("The integer Number is : %d",i);

              1 Reply Last reply
              0
              • M monageasmear

                sorry can you please post the code example int fig = 2; string string1; thanks

                T Offline
                T Offline
                Tim Smith
                wrote on last edited by
                #7

                Don't use streamstring, it is VERY SLOW. sprintf works must faster. Tim Smith I'm going to patent thought. I have yet to see any prior art.

                1 Reply Last reply
                0
                • M monageasmear

                  sorry im new to c++i no this is a simple problem but help would be greatly appreciated convert an int to a string? cheers

                  T Offline
                  T Offline
                  Tim Smith
                  wrote on last edited by
                  #8

                  The fastest method is the following: int i = 5135; char String [64]; // REALLY big number :) _itoa (i, String, 10); Using the other methods discussed are slow and involve the memory manager which will cause all sorts of performance issues. Tim Smith I'm going to patent thought. I have yet to see any prior art.

                  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