CString question

L

lallous

Terry chan said:
Hi,
How to convert String object to MFC CString? and from CString to String?

Thanks!

chan
AFAIK both have methods that return a zero terminated string.
CString s;
(LPCTSTR) s <--- zero terminated string
std::string s;
s.c_str() <-- zero terminated string

HTH,
Elias
 
T

Terry chan

Hi,
How to convert String object to MFC CString? and from CString to String?

Thanks!

chan
 
J

jeffc

Terry chan said:
Hi,
How to convert String object to MFC CString? and from CString to String?

Well, there isn't a "String". There's a "string". If "String" is something
you invented, then you'll have to check the MFC documentation and figure it
out. If you're talking about "string" from the C++ standard library, then
you'll have to compare the available methods for string and CString and see
how they convert.
 
C

Chris Theis

lallous said:
AFAIK both have methods that return a zero terminated string.
CString s;
(LPCTSTR) s <--- zero terminated string

Just to straighen things out - this is not a method but rather an
implemented conversion operation.
std::string s;
s.c_str() <-- zero terminated string

HTH,
Elias

To get a CString (which is OT here!) into a standard string you can do the
following

string MyStr( (const char*)MyCStringObject );

HTH
Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top