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. LPCSTR

LPCSTR

Scheduled Pinned Locked Moved C / C++ / MFC
tutorial
5 Posts 3 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.
  • V Offline
    V Offline
    vtalau
    wrote on last edited by
    #1

    I have a difficulty... when I want to make a LPCSTR variable, I do this: LPCSTR test = TEXT ("hello"); Now I want to make a LPCSTR,including "hello" + name of a persion, which changes every time. I can't do below: CString name = "John"; LPCSTR test = TEXT ("hello" + name); or CString name = "John"; name = "hello" + name LPCSTR test = TEXT (name); please tell me how to do to achieve that result, or show me some pages related to changes of LPCSTR.

    N R 2 Replies Last reply
    0
    • V vtalau

      I have a difficulty... when I want to make a LPCSTR variable, I do this: LPCSTR test = TEXT ("hello"); Now I want to make a LPCSTR,including "hello" + name of a persion, which changes every time. I can't do below: CString name = "John"; LPCSTR test = TEXT ("hello" + name); or CString name = "John"; name = "hello" + name LPCSTR test = TEXT (name); please tell me how to do to achieve that result, or show me some pages related to changes of LPCSTR.

      N Offline
      N Offline
      Nibu babu thomas
      wrote on last edited by
      #2

      vtalau wrote:

      CString name = "John"; LPCSTR test = TEXT ("hello" + name);

      This should not be done. Always use TCHAR types with TEXT and _T, else when you compile with _UNICODE defined it could lead to waste of time. You can do likewise...

      CString name = _T( "Nibu " );
      name += _T( "Hello" );
      LPCTSTR test = name;

      There is no need to wrap name inside TEXT(). You should be careful when using statements like

      LPCSTR test = name; // This will be fine till you do a unicode build.

      So always adopt a generic approach. Try to use _T() or TEXT() wherever possible along with their counterparts like LPCTSTR.


      Nibu thomas A Developer Programming tips[^]  My site[^]

      R 1 Reply Last reply
      0
      • V vtalau

        I have a difficulty... when I want to make a LPCSTR variable, I do this: LPCSTR test = TEXT ("hello"); Now I want to make a LPCSTR,including "hello" + name of a persion, which changes every time. I can't do below: CString name = "John"; LPCSTR test = TEXT ("hello" + name); or CString name = "John"; name = "hello" + name LPCSTR test = TEXT (name); please tell me how to do to achieve that result, or show me some pages related to changes of LPCSTR.

        R Offline
        R Offline
        Rage
        wrote on last edited by
        #3

        vtalau wrote:

        TEXT

        Never seen this...

        CString str="Hello "+name;
        LPCTSTR string = str.operator LPCTSTR();

        or

        CString str="Hello "+name;
        LPCTSTR string = (LPCTSTR)str;

        Also, see this[^]

        ~RaGE();

        I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus

        1 Reply Last reply
        0
        • N Nibu babu thomas

          vtalau wrote:

          CString name = "John"; LPCSTR test = TEXT ("hello" + name);

          This should not be done. Always use TCHAR types with TEXT and _T, else when you compile with _UNICODE defined it could lead to waste of time. You can do likewise...

          CString name = _T( "Nibu " );
          name += _T( "Hello" );
          LPCTSTR test = name;

          There is no need to wrap name inside TEXT(). You should be careful when using statements like

          LPCSTR test = name; // This will be fine till you do a unicode build.

          So always adopt a generic approach. Try to use _T() or TEXT() wherever possible along with their counterparts like LPCTSTR.


          Nibu thomas A Developer Programming tips[^]  My site[^]

          R Offline
          R Offline
          Rage
          wrote on last edited by
          #4

          Nibu babu thomas wrote:

          name += _T( "Hello" );

          Just a detail, but this should be

          name = L("Hello")+name;

          otherwise: "Nibu Hello" :rolleyes:

          ~RaGE();

          I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus

          N 1 Reply Last reply
          0
          • R Rage

            Nibu babu thomas wrote:

            name += _T( "Hello" );

            Just a detail, but this should be

            name = L("Hello")+name;

            otherwise: "Nibu Hello" :rolleyes:

            ~RaGE();

            I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus

            N Offline
            N Offline
            Nibu babu thomas
            wrote on last edited by
            #5

            Rage wrote:

            otherwise: "Nibu Hello"

            :-D


            Nibu thomas A Developer Programming tips[^]  My site[^]

            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