c_str() from CString

  • Thread starter Thread starter Daniel =?iso-8859-1?Q?Lidstr=F6m?=
  • Start date Start date
D

Daniel =?iso-8859-1?Q?Lidstr=F6m?=

Hi,

how can I get the c_str() from a CString? The only way I've found is this:
const char* str = (LPCSTR)cstring;
 
Hi,

how can I get the c_str() from a CString? The only way I've found is this:
const char* str = (LPCSTR)cstring;

May I enquire what your purpose for this would be? It may influence the
answers you receive if we new what you were actually trying to accomplish
in a more fleshed out context :)
 
May I enquire what your purpose for this would be? It may influence the
answers you receive if we new what you were actually trying to accomplish
in a more fleshed out context :)

I want to put the contents of a CString into my own String class, or a
std::string.
 
const char* str = (LPCSTR)cstring;
I want to put the contents of a CString into my own String class, or a
std::string.

The cast to LPCSTR will do.

But if the application is Unicode, you will run into problems.
You should use LPCTSTR to be generic. Also, you should
provide a way to use std::wstring for Unicode application and
std::string for ANSI applications.

Same notes for your own class.
 
Back
Top