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. ATL / WTL / STL
  4. stl version of CString?

stl version of CString?

Scheduled Pinned Locked Moved ATL / WTL / STL
c++algorithmsquestiondiscussionannouncement
9 Posts 6 Posters 2 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.
  • N Offline
    N Offline
    Nitron
    wrote on last edited by
    #1

    First off: STL RULES! Ok, now a confession... the only reason I even use MFC is for CString. I've been searching for a decent stl replacement, and found a few, but I thought I'd ask some STL zealots for their respective opinions... - Nitron


    "Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb

    M 1 Reply Last reply
    0
    • N Nitron

      First off: STL RULES! Ok, now a confession... the only reason I even use MFC is for CString. I've been searching for a decent stl replacement, and found a few, but I thought I'd ask some STL zealots for their respective opinions... - Nitron


      "Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      A quick & dirty replacement is:

      typedef std::basic_string<TCHAR> tstring;

      although I think I've seen a true STL port here on CP. --Mike-- The Internet is a place where absolutely nothing happens.   -- Strong Bad 1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click! My really out-of-date homepage Sonork-100.19012 Acid_Helm

      A N 2 Replies Last reply
      0
      • M Michael Dunn

        A quick & dirty replacement is:

        typedef std::basic_string<TCHAR> tstring;

        although I think I've seen a true STL port here on CP. --Mike-- The Internet is a place where absolutely nothing happens.   -- Strong Bad 1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click! My really out-of-date homepage Sonork-100.19012 Acid_Helm

        A Offline
        A Offline
        Alexandru Savescu
        wrote on last edited by
        #3

        Michael Dunn wrote: typedef std::basic_string<TCHAR> tstring; That's not enough. CString uses reference counting remember? Best regards, Alexandru Savescu P.S. Interested in art? Visit this!

        T 1 Reply Last reply
        0
        • A Alexandru Savescu

          Michael Dunn wrote: typedef std::basic_string<TCHAR> tstring; That's not enough. CString uses reference counting remember? Best regards, Alexandru Savescu P.S. Interested in art? Visit this!

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

          Well, depending on your application, reference counting can be slower. Herb Sutter did a study and found that reference counting based strings only benefit the application if you application is primarily copying the string from place to place without modification. But you also have to take into account any memory savings that you might get with a reference counting system. Tim Smith I'm going to patent thought. I have yet to see any prior art.

          1 Reply Last reply
          0
          • M Michael Dunn

            A quick & dirty replacement is:

            typedef std::basic_string<TCHAR> tstring;

            although I think I've seen a true STL port here on CP. --Mike-- The Internet is a place where absolutely nothing happens.   -- Strong Bad 1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click! My really out-of-date homepage Sonork-100.19012 Acid_Helm

            N Offline
            N Offline
            Nitron
            wrote on last edited by
            #5

            Actually, to be even more specific, I use CString mainly for the method:

            szMyString.Format("My unsigned int is 0x%.8X", uiMyInt);

            ...and for some reason sprintf() scares me :~ - Nitron


            "Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb

            B 1 Reply Last reply
            0
            • N Nitron

              Actually, to be even more specific, I use CString mainly for the method:

              szMyString.Format("My unsigned int is 0x%.8X", uiMyInt);

              ...and for some reason sprintf() scares me :~ - Nitron


              "Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb

              B Offline
              B Offline
              Ben Burnett
              wrote on last edited by
              #6

              std::ostringstream oss;
              oss << "My unsigned int is 0x" << std::uppercase << std::setw ( 8 )
              << std::setfill ( '0' ) << std::hex << n << std::endl;
              std::cout << oss.str () << std::endl;

              Is roughly the equivalent when using the STLs. It a bit of a mouth full, but some of the modifiers persist between calls--std::uppercase will, while std::setw must be called each time--so once you called them, you need not do so again untill you need a new option set. cheers, -B

              N 1 Reply Last reply
              0
              • B Ben Burnett

                std::ostringstream oss;
                oss << "My unsigned int is 0x" << std::uppercase << std::setw ( 8 )
                << std::setfill ( '0' ) << std::hex << n << std::endl;
                std::cout << oss.str () << std::endl;

                Is roughly the equivalent when using the STLs. It a bit of a mouth full, but some of the modifiers persist between calls--std::uppercase will, while std::setw must be called each time--so once you called them, you need not do so again untill you need a new option set. cheers, -B

                N Offline
                N Offline
                Nitron
                wrote on last edited by
                #7

                Ben Burnett wrote: It a bit of a mouth full, I agree. Maybe I will have to attempt my own STL replacement for CString... hmmm, possible article :suss: - Nitron


                "Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb

                B N 2 Replies Last reply
                0
                • N Nitron

                  Ben Burnett wrote: It a bit of a mouth full, I agree. Maybe I will have to attempt my own STL replacement for CString... hmmm, possible article :suss: - Nitron


                  "Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb

                  B Offline
                  B Offline
                  Ben Burnett
                  wrote on last edited by
                  #8

                  Nitron wrote: Maybe I will have to attempt my own STL replacement for CString... Before you dig in, check out the Boost Format library[^]. It might just be what you're looking for. cheers, -B

                  1 Reply Last reply
                  0
                  • N Nitron

                    Ben Burnett wrote: It a bit of a mouth full, I agree. Maybe I will have to attempt my own STL replacement for CString... hmmm, possible article :suss: - Nitron


                    "Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb

                    N Offline
                    N Offline
                    Nick Parker
                    wrote on last edited by
                    #9

                    Nitron wrote: Maybe I will have to attempt my own STL replacement for CString... Sounds like more than one nights worth of work. ;)


                    Nick Parker

                    The only man who never makes a mistake is the man who never does anything. - Theodore Roosevelt

                    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