Cstring convert to string

J

jerry

Hi,

How to convert from CString to stl string?

i wrote some codes as below:

CString Temp = "This is a test";

string Str = Temp;

they 's an error when i compile it, it says:
error C2440: 'initializing' : cannot convert from 'CString' to
'std::basic_string<_Elem,_Traits,_Ax>'

could you give me a solution ? thankyou
 
A

Alf P. Steinbach

* jerry:
How to convert from CString to stl string?

i wrote some codes as below:

CString Temp = "This is a test";

string Str = Temp;

they 's an error when i compile it, it says:
error C2440: 'initializing' : cannot convert from 'CString' to
'std::basic_string<_Elem,_Traits,_Ax>'

could you give me a solution ? thankyou

Check what arguments the std::string constructors require.

Find out how you can retrieve the relevant information from a CString.

That's it.

By the way, note that 'CString' is a non-standard class.

One might *guess* that it's a Microsoft MFC/ATL 'CString', but there are dozens
of like beasts, and discussing any of them is off-topic in this group.


Cheers & hth.,

- Alf
 
A

AnonMail2005

Hi,

How to convert from CString to stl string?

i wrote some codes as below:

CString Temp = "This is a test";

string Str = Temp;

they 's an error when i compile it, it says:
error C2440: 'initializing' : cannot convert from 'CString' to
'std::basic_string<_Elem,_Traits,_Ax>'

could you give me a solution ? thankyou

Most third party "string" implementations allow you to get at a
pointer that points to a null terminated C-style string. Some may not
be null terminated but return the pointer plus a length. From there,
you can construct a std::string. Just look up the various
constructors for std::string.

HTH
 
J

jerry

* jerry:









Check what arguments the std::string constructors require.

Find out how you can retrieve the relevant information from a CString.

That's it.

By the way, note that 'CString' is a non-standard class.

One might *guess* that it's a Microsoft MFC/ATL 'CString', but there are dozens
of like beasts, and discussing any of them is off-topic in this group.

Cheers & hth.,

- Alf


YOU SAID IT, CString is mfc class;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top