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. STL string

STL string

Scheduled Pinned Locked Moved C / C++ / MFC
c++
10 Posts 7 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.
  • A Offline
    A Offline
    act_x
    wrote on last edited by
    #1

    IS there a way I can do the analogous of sprintf for a char * to a STL string . or a Format for a CString Basically i want to write a integer value to a string ! string numText; char data[20]; int a =100; sprintf(data,"Num is %d",data); Is there a way to do this for the string numText !!!!

    N N K R 4 Replies Last reply
    0
    • A act_x

      IS there a way I can do the analogous of sprintf for a char * to a STL string . or a Format for a CString Basically i want to write a integer value to a string ! string numText; char data[20]; int a =100; sprintf(data,"Num is %d",data); Is there a way to do this for the string numText !!!!

      N Offline
      N Offline
      Nathan Blomquist
      wrote on last edited by
      #2

      you could try: string numText; char data[20]; int a = 100; sprintf(data,"Num is %d",a); numText = string(data); // this copies the char array into the string -Nathan --------------------------- Hmmm... what's a signature?

      1 Reply Last reply
      0
      • A act_x

        IS there a way I can do the analogous of sprintf for a char * to a STL string . or a Format for a CString Basically i want to write a integer value to a string ! string numText; char data[20]; int a =100; sprintf(data,"Num is %d",data); Is there a way to do this for the string numText !!!!

        N Offline
        N Offline
        Nemanja Trifunovic
        wrote on last edited by
        #3

        Tkae a look at This article[^]

        J 1 Reply Last reply
        0
        • A act_x

          IS there a way I can do the analogous of sprintf for a char * to a STL string . or a Format for a CString Basically i want to write a integer value to a string ! string numText; char data[20]; int a =100; sprintf(data,"Num is %d",data); Is there a way to do this for the string numText !!!!

          K Offline
          K Offline
          Kevin McFarlane
          wrote on last edited by
          #4

          int main(int argc, char* argv[])
          {
          ostringstream s;
          int a = 100;
          s << a;
          string numText = s.str();
          cout << numText << endl;

          return 0;
          }

          Oh, you also need to include the iostream and sstream headers. Kevin

          1 Reply Last reply
          0
          • A act_x

            IS there a way I can do the analogous of sprintf for a char * to a STL string . or a Format for a CString Basically i want to write a integer value to a string ! string numText; char data[20]; int a =100; sprintf(data,"Num is %d",data); Is there a way to do this for the string numText !!!!

            R Offline
            R Offline
            Ryan Binns
            wrote on last edited by
            #5

            Use a ostringstream.

            Ryan

            "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

            1 Reply Last reply
            0
            • N Nemanja Trifunovic

              Tkae a look at This article[^]

              J Offline
              J Offline
              Johann Gerell
              wrote on last edited by
              #6

              And on Windows CE .NET? The STL implementation there lacks the handy streams... -- Human beings, who are almost unique in having the ability
              to learn from the experience of others, are also remarkable
              for their apparent disinclination to do so. (Douglas Adams)

              J 1 Reply Last reply
              0
              • J Johann Gerell

                And on Windows CE .NET? The STL implementation there lacks the handy streams... -- Human beings, who are almost unique in having the ability
                to learn from the experience of others, are also remarkable
                for their apparent disinclination to do so. (Douglas Adams)

                J Offline
                J Offline
                jhwurmbach
                wrote on last edited by
                #7

                Johann Gerell wrote: And on Windows CE .NET? You would use .NET classes anyway. Otherwise, whats the point of using a .NET platform?


                Who is 'General Failure'? And why is he reading my harddisk?!?

                J 1 Reply Last reply
                0
                • J jhwurmbach

                  Johann Gerell wrote: And on Windows CE .NET? You would use .NET classes anyway. Otherwise, whats the point of using a .NET platform?


                  Who is 'General Failure'? And why is he reading my harddisk?!?

                  J Offline
                  J Offline
                  Johann Gerell
                  wrote on last edited by
                  #8

                  jhwurmbach wrote: You would use .NET classes anyway No. ".NET" is a product name here, the .NET framework need not have anything to do with it, but it can. In our specific case, (a) the compact framework (.NET CF) is buggy and unusable and (b) we do drivers and low level stuff unapropriate for the CF. jhwurmbach wrote: Otherwise, whats the point of using a .NET platform? Since it's the latest version of Windows CE, it offers greater security, better Internet connectivity, more stability and about a gazillion other stuff of interest to mobile developers. -- Human beings, who are almost unique in having the ability
                  to learn from the experience of others, are also remarkable
                  for their apparent disinclination to do so. (Douglas Adams)

                  J 1 Reply Last reply
                  0
                  • J Johann Gerell

                    jhwurmbach wrote: You would use .NET classes anyway No. ".NET" is a product name here, the .NET framework need not have anything to do with it, but it can. In our specific case, (a) the compact framework (.NET CF) is buggy and unusable and (b) we do drivers and low level stuff unapropriate for the CF. jhwurmbach wrote: Otherwise, whats the point of using a .NET platform? Since it's the latest version of Windows CE, it offers greater security, better Internet connectivity, more stability and about a gazillion other stuff of interest to mobile developers. -- Human beings, who are almost unique in having the ability
                    to learn from the experience of others, are also remarkable
                    for their apparent disinclination to do so. (Douglas Adams)

                    J Offline
                    J Offline
                    jhwurmbach
                    wrote on last edited by
                    #9

                    Wow! .NET CF comes without .NET. Microsoft marketing is working really hard on creating a strong brand. I did not know that. And on top of it, you do not even get a C++ compiler (that would include iostreams), just a surrogate. It seems you are stuck with sprintf.


                    Who is 'General Failure'? And why is he reading my harddisk?!?

                    J 1 Reply Last reply
                    0
                    • J jhwurmbach

                      Wow! .NET CF comes without .NET. Microsoft marketing is working really hard on creating a strong brand. I did not know that. And on top of it, you do not even get a C++ compiler (that would include iostreams), just a surrogate. It seems you are stuck with sprintf.


                      Who is 'General Failure'? And why is he reading my harddisk?!?

                      J Offline
                      J Offline
                      Johann Gerell
                      wrote on last edited by
                      #10

                      jhwurmbach wrote: And on top of it, you do not even get a C++ compiler (that would include iostreams), just a surrogate :(( jhwurmbach wrote: It seems you are stuck with sprintf Believe me, I'm so aware of that fact... -- Human beings, who are almost unique in having the ability
                      to learn from the experience of others, are also remarkable
                      for their apparent disinclination to do so. (Douglas Adams)

                      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