Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Cstring convert to string

Reply
Thread Tools

Cstring convert to string

 
 
jerry
Guest
Posts: n/a
 
      05-16-2009
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
 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      05-16-2009
* 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

--
Due to hosting requirements I need visits to <url: http://alfps.izfree.com/>.
No ads, and there is some C++ stuff! Just going there is good. Linking
to it is even better! Thanks in advance!
 
Reply With Quote
 
 
 
 
AnonMail2005@gmail.com
Guest
Posts: n/a
 
      05-16-2009
On May 16, 10:42*am, jerry <(E-Mail Removed)> wrote:
> 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
 
Reply With Quote
 
jerry
Guest
Posts: n/a
 
      05-17-2009
On May 16, 10:46*pm, "Alf P. Steinbach" <(E-Mail Removed)> wrote:
> * 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
>
> --
> Due to hosting requirements I need visits to <url:http://alfps.izfree.com/>.
> No ads, and there is some C++ stuff! Just going there is good. Linking
> to it is even better! Thanks in advance!



YOU SAID IT, CString is mfc class;
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to convert CString to LPCWSTR 月夕 C++ 3 07-06-2009 05:28 PM
Convert CString to Variant Gertjan Huiskes C++ 1 01-04-2007 10:06 PM
convert VARIANT to CSTRING michael mazanek C++ 1 09-18-2006 05:52 PM
How to convert CString to an ASCII character string? jt C++ 2 07-14-2005 05:36 AM
? CString to char* in Unicode; How to convert? Markus Hmmerli C++ 6 09-04-2003 08:31 PM



Advertisments