convert cstring to char*

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jul 2008
Posts: 46
Reputation: karang is an unknown quantity at this point 
Solved Threads: 0
karang karang is offline Offline
Light Poster

convert cstring to char*

 
0
  #1
Dec 17th, 2008
Hi

How to convert CString to char* in C++

Regards
Karan
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 320
Reputation: cikara21 is an unknown quantity at this point 
Solved Threads: 63
cikara21's Avatar
cikara21 cikara21 is offline Offline
Posting Whiz

Re: convert cstring to char*

 
0
  #2
Dec 17th, 2008
simply
  1. CString str = "Check";
  2. char *my_char = new char[];
  3. sprint(my_char,"%ls",str.GetBuffer());
.:-cikara21-:.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: convert cstring to char*

 
0
  #3
Dec 17th, 2008
> char *my_char = new char[];
What does this do again?
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 320
Reputation: cikara21 is an unknown quantity at this point 
Solved Threads: 63
cikara21's Avatar
cikara21 cikara21 is offline Offline
Posting Whiz

Re: convert cstring to char*

 
0
  #4
Dec 18th, 2008
To allocate n bytes of storage suitably aligned to represent any array object of that size or smaller. The program can define a function with this function signature that replaces the default version defined by the Standard C++ Library. The required behavior is the same as for operator new(unsigned int). The default behavior is to return operator new(n).
.:-cikara21-:.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: convert cstring to char*

 
0
  #5
Dec 18th, 2008
And if you don't specify an n, then what?
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 320
Reputation: cikara21 is an unknown quantity at this point 
Solved Threads: 63
cikara21's Avatar
cikara21 cikara21 is offline Offline
Posting Whiz

Re: convert cstring to char*

 
0
  #6
Dec 18th, 2008
Originally Posted by Salem View Post
And if you don't specify an n, then what?
I apologize, May I ask u some question..
??? What the difference between :
  1. char *my_char = new char(5);
  2. // and..
  3. char *my_char = new char[5];
??? In this case. Isn't it true that is same as :
  1. char *my_char = new char();
  2. // or...
  3. char *my_char = new char[];
Last edited by cikara21; Dec 18th, 2008 at 5:10 am.
.:-cikara21-:.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: convert cstring to char*

 
0
  #7
Dec 18th, 2008
> char *my_char = new char(5);
1 char, initialised to (char)5

> char *my_char = new char[5];
5 chars, initialised with the default ctor

> char *my_char = new char();
1 char, initialised with the default ctor

> char *my_char = new char[];
Does it even compile?
I've no idea what you get if it does.

I'm pretty sure that what it ISN'T is an infinitely large array you can appy write as much data as you want to without incident.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 320
Reputation: cikara21 is an unknown quantity at this point 
Solved Threads: 63
cikara21's Avatar
cikara21 cikara21 is offline Offline
Posting Whiz

Re: convert cstring to char*

 
0
  #8
Dec 18th, 2008
about char *my_char = new char[]; yes. it does compile...

I just confuse with the statement below..

To allocate n bytes of storage suitably aligned to represent any array object of that size or smaller. The program can define a function with this function signature that replaces the default version defined by the Standard C++ Library. The required behavior is the same as for operator new(unsigned int) . The default behavior is to return operator new(n).

but thanks..
.:-cikara21-:.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC