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. Which type of string do you use in VC++ project?

Which type of string do you use in VC++ project?

Scheduled Pinned Locked Moved C / C++ / MFC
c++comquestion
13 Posts 8 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.
  • Z zengkun100

    There are too many string types you can use in your VC++ project. STL and many other non-MS libs use string class; MFC prefers CString; when it comes to COM, you will see _bstr_t and BSTR. …… Many code in my project just do string conversions——convert from one string type to another, which makes me fell ugly. Hello everyone, which is your favorite string type? :-D

    A Chinese VC++ programmer

    CPalliniC Online
    CPalliniC Online
    CPallini
    wrote on last edited by
    #4

    TCHAR* :-D

    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.
    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

    In testa che avete, signor di Ceprano?

    Z 1 Reply Last reply
    0
    • _ _AnsHUMAN_

      STL's basic_string template class is much more flexible in this respect and allows you to create any kind of the strings suitable for specific scenarios. You can use CString if the size of the project is going to be small. In case the project is a large one than I would rather prefer a wrapper class to encapsulate all the functionality and use it. BSTR's are used in COM.It's better to convert the CString to a _bstr_t and then pass it to the COM interface if you are working with COM since they have to maintain compatibility with VB datatypes and components can be invoked from there.

      Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

      Z Offline
      Z Offline
      zengkun100
      wrote on last edited by
      #5

      Thank you! Your suggestion is very constructive. :-D I do like STL's basic_string, but I have to use its c_str() memfunc when I pass a string object to MFC classes. :(

      A Chinese VC++ programmer

      1 Reply Last reply
      0
      • CPalliniC CPallini

        TCHAR* :-D

        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.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

        Z Offline
        Z Offline
        zengkun100
        wrote on last edited by
        #6

        I believe you're not serious :laugh:

        A Chinese VC++ programmer

        CPalliniC 1 Reply Last reply
        0
        • Z zengkun100

          I believe you're not serious :laugh:

          A Chinese VC++ programmer

          CPalliniC Online
          CPalliniC Online
          CPallini
          wrote on last edited by
          #7

          You're wrong. (Well, I often have to use one or more of the classes you were talking about, but usually I prefer going to the metal) :laugh:

          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.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

          In testa che avete, signor di Ceprano?

          Z 1 Reply Last reply
          0
          • CPalliniC CPallini

            You're wrong. (Well, I often have to use one or more of the classes you were talking about, but usually I prefer going to the metal) :laugh:

            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.
            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

            Z Offline
            Z Offline
            zengkun100
            wrote on last edited by
            #8

            I know what you're mean. :) Thank you!

            A Chinese VC++ programmer

            1 Reply Last reply
            0
            • Z zengkun100

              There are too many string types you can use in your VC++ project. STL and many other non-MS libs use string class; MFC prefers CString; when it comes to COM, you will see _bstr_t and BSTR. …… Many code in my project just do string conversions——convert from one string type to another, which makes me fell ugly. Hello everyone, which is your favorite string type? :-D

              A Chinese VC++ programmer

              O Offline
              O Offline
              Ozer Karaagac
              wrote on last edited by
              #9

              Maybe, you may want to consider this. http://www.ski-epic.com/templates_stl_rant/index.html[^]

              J 1 Reply Last reply
              0
              • Z zengkun100

                There are too many string types you can use in your VC++ project. STL and many other non-MS libs use string class; MFC prefers CString; when it comes to COM, you will see _bstr_t and BSTR. …… Many code in my project just do string conversions——convert from one string type to another, which makes me fell ugly. Hello everyone, which is your favorite string type? :-D

                A Chinese VC++ programmer

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

                I don't really like any of them, but use whatever fits best into the current project. For instance, now I work on something with lots of COM, so I use CComBSTR. On the previous job, we were making an OS-portable system, so the obvious choice was std::string.

                Programming Blog utf8-cpp

                1 Reply Last reply
                0
                • Z zengkun100

                  There are too many string types you can use in your VC++ project. STL and many other non-MS libs use string class; MFC prefers CString; when it comes to COM, you will see _bstr_t and BSTR. …… Many code in my project just do string conversions——convert from one string type to another, which makes me fell ugly. Hello everyone, which is your favorite string type? :-D

                  A Chinese VC++ programmer

                  T Offline
                  T Offline
                  toxcct
                  wrote on last edited by
                  #11

                  all depends. i used to strongly abandon C-style strings (char* and all its variants) as long as i can. of course, when I have to use the C runtime (or any C APIs), then it's the only really valid reason to... as long as I code in C++, I use C++ strings. I used to use the MVC pattern also. so, for my UI layer, I mainly use CString as I use MFC. but as for my other layers (which are generally put into DLLs), i use std::string

                  [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                  1 Reply Last reply
                  0
                  • O Ozer Karaagac

                    Maybe, you may want to consider this. http://www.ski-epic.com/templates_stl_rant/index.html[^]

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

                    Ozer Karaagac wrote:

                    Maybe, you may want to consider this.

                    No. That is so old and ugly stuff. Most of it is even for VC6! And look at the second picture (the one named "Screenshots of native C++ equivalent") and how his class MLFString has a equals()-member! :wtf: :~ Somone who programs JAVA in C++ is not someone to whose programming tip I tend to listen!

                    Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all.
                    Douglas Adams, "Dirk Gently's Holistic Detective Agency"

                    O 1 Reply Last reply
                    0
                    • J jhwurmbach

                      Ozer Karaagac wrote:

                      Maybe, you may want to consider this.

                      No. That is so old and ugly stuff. Most of it is even for VC6! And look at the second picture (the one named "Screenshots of native C++ equivalent") and how his class MLFString has a equals()-member! :wtf: :~ Somone who programs JAVA in C++ is not someone to whose programming tip I tend to listen!

                      Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all.
                      Douglas Adams, "Dirk Gently's Holistic Detective Agency"

                      O Offline
                      O Offline
                      Ozer Karaagac
                      wrote on last edited by
                      #13

                      :-O Three negative votes against just sharing an article without revealing any acceptance. Isn't it somewhat harsh? What a great liking to vote negative? Is this STL fanaticism? If so, good luck to you with your lovely STL. In STL we trust. :omg:

                      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