473,394 Members | 1,869 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,394 software developers and data experts.

c_str() from 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;

--
Daniel
Jul 21 '05 #1
3 1853
On Mon, 13 Sep 2004 12:16:08 +0200, Daniel Lidström wrote:
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 :)
--
Tom Shelton [MVP]
Jul 21 '05 #2
On Tue, 14 Sep 2004 00:24:53 -0600, Tom Shelton wrote:
On Mon, 13 Sep 2004 12:16:08 +0200, Daniel Lidström wrote:
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 :)


I want to put the contents of a CString into my own String class, or a
std::string.

--
Daniel
Jul 21 '05 #3
>>> 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.

--
Mihai
-------------------------
Replace _year_ with _ to get the real email
Jul 21 '05 #4

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

Similar topics

2
by: sqwirx | last post by:
I am using a String that has a member function c_str(). Because I think c_str() reduces the readability of the code and I don't want implicit conversions, I'm concidering to add a "char const *...
8
by: Oskar | last post by:
Hi. I`m new in cpp and i have a litlle problem. i have a CString from Edit Box (eg."aaa bbb ccc 7327373 d feaf 323 dvjiv 234") and i want to put the data (space separated) into an array.It shuld...
2
by: diadia | last post by:
string s = "hello"; const char *p = s.begin(); cout << p << endl; // print hello s = ""; char *p2= s.begin(); cout << p2 << endl; // print hello why?????
3
by: nsyforce | last post by:
What is the correct way to convert a const char* to a CString? I'm somewhat of a newbie and have tried several ways. While they all convert ok, I'm using a profiler that shows a memory leak for...
3
by: Daniel Lidström | last post by:
Hi, how can I get the c_str() from a CString? The only way I've found is this: const char* str = (LPCSTR)cstring; -- Daniel
7
by: matish | last post by:
Hi, in: string s("Hi"); const char* c = s.c_str(); how long will the pointed cstring live? I see that calling delete c or delete c fail, that the cstring survives the end of the scope in...
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: 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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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,...
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...
0
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...
0
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...

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.