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. how do i convert a string to LPCSTR?

how do i convert a string to LPCSTR?

Scheduled Pinned Locked Moved C / C++ / MFC
question
3 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.
  • U Offline
    U Offline
    User 404410
    wrote on last edited by
    #1

    :omg:as title

    A R 2 Replies Last reply
    0
    • U User 404410

      :omg:as title

      A Offline
      A Offline
      Anonymous
      wrote on last edited by
      #2

      string? -> std::string? std::string str = "burp"; USES_CONVERSION; LPCSTR lpcstr = T2A(str.c_str());

      1 Reply Last reply
      0
      • U User 404410

        :omg:as title

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

        1. To convert a CString to a LPCSTR

        #include <atlconv.h>

        USES_CONVERSION;
        CString str = _T("Whatever");
        LPCSTR lpsz = T2CA(str);

        2. To convert a std::string to a LPCSTR

        std::string str("Whatever");
        LPCSTR lpsz = str.c_str(); // No T2CA() required - std::string is always ANSI

        3. To convert a std::wstring to a LPCSTR

        #include <atlconv.h>

        USES_CONVERSION;
        std::wstring(L"Whatever");
        LPCSTR lpsz = W2CA(str);

        Hope this helps Have a look at the tutorial on string handling on CP. That will say more :) Ryan Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
        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
        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