473,547 Members | 2,391 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CString question

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

Thanks!

chan
Jul 22 '05 #1
3 1739
"Terry chan" <ct****@cimold. com> wrote in message
news:3f******@u senet.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******@u senet.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.o rg> wrote in message
news:bt******** ****@ID-161723.news.uni-berlin.de...
"Terry chan" <ct****@cimold. com> wrote in message
news:3f******@u senet.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*)MyCString Object );

HTH
Chris
Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
24507
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 = source.GetBuffer(0 ); but i need a char* and so this is not working CString source = _T("TestString");
14
3765
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
3936
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 my function takes mfc's CString I was converting it this way: char __pin* szUser =...
1
3835
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 like this: bool CSUSSWrapper::Init(String* filename, String* username, String* password, String* working) {
0
916
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 problem, but after I created managed C++ dll, I can't use CString at all in the dll. The code blows up at: explicit CSimpleStringT( IAtlStringMgr*
4
4735
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++, there is no complain about the defintion. But
4
11019
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
10483
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 tried throwing in a bunch of #includes but didn't help. Here's the compiler errors: Compiling...
9
7925
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 following format,
0
7510
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7703
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7463
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7797
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6032
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5362
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5081
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3493
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1050
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.