471,585 Members | 1,457 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,585 software developers and data experts.

CString question

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

Thanks!

chan
Jul 22 '05 #1
3 1677
"Terry chan" <ct****@cimold.com> wrote in message
news:3f******@usenet.ugs.com...
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
Jul 22 '05 #2

"Terry chan" <ct****@cimold.com> wrote in message
news:3f******@usenet.ugs.com...
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.
Jul 22 '05 #3

"lallous" <la*****@lgwm.org> wrote in message
news:bt************@ID-161723.news.uni-berlin.de...
"Terry chan" <ct****@cimold.com> wrote in message
news:3f******@usenet.ugs.com...
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


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
Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Markus Hämmerli | last post: by
14 posts views Thread by Toro | last post: by
reply views Thread by zhenlee | last post: by
4 posts views Thread by Cactus | last post: by
4 posts views Thread by Susan Rice | last post: by
9 posts views Thread by Donos | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.