473,378 Members | 1,387 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,378 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 1850
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.