473,387 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 1728
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Markus Hämmerli | last post by:
I ' ll tra to convert a Cstring to char* without success. I working in a Unicode enabled environment this is working in Unicode CString source = _T("TestString"); TCHAR *szSource =...
14
by: Toro | last post by:
1) say, CString b; char * a; how do I assign b into a ? strcpy(a,b) has no problem in compiling but I don't get what I want. 2) I used char ** argv
2
by: mirek | last post by:
Hi, I'm trying to import my old code to the .NET using managed wrappers. I've read "Managed Extensions for C++ Migration Guide" document and was trying to do what it stated in it. For example if...
1
by: SteveK | last post by:
Trying to wrap an unmanaged class. Here is the function I'm trying to wrap: bool Init(PCSTR filename, PCSTR username, PCSTR password, PCSTR working); In my managed C++ class, I have a method...
0
by: zhenlee | last post by:
Hi all, If this question has been discussed before, I appologize for that, please point me to the correct direction. If I created Managed C++ console application, I can use ATL::CString no...
4
by: huguogang | last post by:
Just curious, any one know what the 3 part parameter "class CString filename" would mean. The code: int TestFunc(class CString filename) { fopen(filename, "w"); } Compile using Visaul C++,...
4
by: Cactus | last post by:
How to convert unsigned char* to CString: I wrote some function: u_char_ =55; u_char_ =66; u_char_ =77; .........=ii...... Convert_to_CS(u_char_);
4
by: Susan Rice | last post by:
I'm new to using CString. Why won't the following compile? I'm using Microsoft Visual C++ 6.0 Line 37 which it complains about is the function: 37 CString ConvertFile(char *szFileName) I...
9
by: Donos | last post by:
I have a CString with 100 characters. Now i want to make that to 2 lines. For example, CString str = "This is just a test to find out how to break a cstring"; I want this CString in the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.