Hi

How to convert CString to char* in C++

Regards
Karan

simply

CString str = "Check";
char *my_char = new char[];
sprint(my_char,"%ls",str.GetBuffer());

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).

And if you don't specify an n, then what?

I apologize, May I ask u some question..
??? What the difference between :

char *my_char = new char(5);
       // and..
       char *my_char = new char[5];

??? In this case. Isn't it true that is same as :

char *my_char = new char();
      // or...
      char *my_char = new char[];

> 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.

about char *my_char = new char[]; yes. it does compile...:-O

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..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.