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 integer value to string objcet?

convert integer value to string objcet?

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
6 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.
  • Y Offline
    Y Offline
    Yonggoo
    wrote on last edited by
    #1

    Hi All, Is there any function in (standard) c++ that convert integer value to std:string object? Such as, ... int n = 123; string str_n = itos(n); ... or some efficient way? Thanks!

    Yonggoo

    L C 2 Replies Last reply
    0
    • Y Yonggoo

      Hi All, Is there any function in (standard) c++ that convert integer value to std:string object? Such as, ... int n = 123; string str_n = itos(n); ... or some efficient way? Thanks!

      Yonggoo

      L Offline
      L Offline
      lucy 0
      wrote on last edited by
      #2

      I would use str_n.Format ("%d", n)

      S C H 3 Replies Last reply
      0
      • L lucy 0

        I would use str_n.Format ("%d", n)

        S Offline
        S Offline
        Sceptic Mole
        wrote on last edited by
        #3

        lucy wrote:

        I would use str_n.Format ("%d", n)

        CString needed, not string

        1 Reply Last reply
        0
        • Y Yonggoo

          Hi All, Is there any function in (standard) c++ that convert integer value to std:string object? Such as, ... int n = 123; string str_n = itos(n); ... or some efficient way? Thanks!

          Yonggoo

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          Yes, an ostringstream would do that. http://www.codeproject.com/vcpp/stl/ostringstream.asp[^]

          Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert

          1 Reply Last reply
          0
          • L lucy 0

            I would use str_n.Format ("%d", n)

            C Offline
            C Offline
            CPallini
            wrote on last edited by
            #5

            lucy wrote:

            str_n.Format ("%d", n)

            I think that std::string has not such Format method. Maybe you're writing about CString, Aren't you? By the way, I think the OP can use a stringstream object, for instance:

            std::stringstream ss;
            std::string s;
            ss << 5;
            ss >> s;

            But I don't know how efficient this way is. :)

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

            1 Reply Last reply
            0
            • L lucy 0

              I would use str_n.Format ("%d", n)

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

              I think you use of CString ;)


              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