-
September 3rd, 2009, 04:59 AM
#1
How to assign CString to wstring UNICODE compilation
I have a project originally compiled ANSI, it now needs to support UNICODE.
The front end is MFC and some of the backend is std C++ stl.
Currenty under ASCII compilation I have something like:
std:string val;
CString src;
val = src;
No problem.
When compile under UNICODE then have
std::wstring val
CString src
val = src;
Wont compile.
error C2679: binary '=' : no operator found which takes a right-hand operand of type 'CString' (or there is no acceptable conversion)
Can anyone help please?
Thanks.
-
September 3rd, 2009, 05:52 AM
#2
Re: How to assign CString to wstring UNICODE compilation
Originally Posted by PRMARJORAM
...
When compile under UNICODE then have
...
How do you compile "under UNICODE"?
Did you defined both UNICODE and _UNICODE?
Victor Nijegorodov
-
September 3rd, 2009, 06:06 AM
#3
Re: How to assign CString to wstring UNICODE compilation
Originally Posted by VictorN
How do you compile "under UNICODE"?
Did you defined both UNICODE and _UNICODE?
Im using the Visual studio 2005 compiler, so just switched the setting in the general options to the unicode character set and recompiled.
Although have edited my String typedef from std::string to std::wstring
-
September 3rd, 2009, 06:24 AM
#4
Re: How to assign CString to wstring UNICODE compilation
CString is #ifdef'd to be synonymous to CStringA or to CStringW depending on settings. As victor indicates, this could be the problem.
Try literally changing yoru CString to CStringW in this particular case and retry. if it solves the issue, you need to get your compile settings corrected, if the error remains, then maybe there isn't an available (automatic) conversion available. In that case, you may need to explicitely typecast every CString to stringw conversion.
-
September 3rd, 2009, 06:35 AM
#5
Re: How to assign CString to wstring UNICODE compilation
I tried CStringW, made no difference.
putting a typecast in front of the 'CStringW' also generates an error
I assume you mean
std::wstring val
CStringW src
val = (std::wstring)src;
error C2679: binary '=' : no operator found which takes a right-hand operand of type 'std::basic_string<_Elem,_Traits,_Ax>' (or there is no acceptable conversion)
-
September 3rd, 2009, 06:52 AM
#6
Re: How to assign CString to wstring UNICODE compilation
std::wstring val
CString src
val = src.c_str();
-
September 3rd, 2009, 06:58 AM
#7
Re: How to assign CString to wstring UNICODE compilation
I guess. you meant:
Code:
std::wstring val
CString src
src= val .c_str();
And from CStringW to std::wstring:
Code:
std::wstring val;
CStringW src;
val = (LPCWSTR)src;
Victor Nijegorodov
-
September 3rd, 2009, 06:58 AM
#8
Re: How to assign CString to wstring UNICODE compilation
Originally Posted by 0xC0000005
std::wstring val
CString src
val = src.c_str();
CString not have the c_str() method!
error C2039: 'c_str' : is not a member of 'ATL::CStringT<BaseType,StringTraits>'
-
September 3rd, 2009, 07:12 AM
#9
Re: How to assign CString to wstring UNICODE compilation
Thanks seems to be working now.
In the std C++ libs now, got lots of errors where have changed to wstring.
Got to put an L in front of any string literals.
And any str function calls got to be changed to wcs version.
Cant see we will ever go back to ASCII so dont need to control all this via some preprocessor directive.
But is this all I need to do? Are there any unforseen problems?
Thanks for your help.
-
September 7th, 2009, 05:53 AM
#10
Re: How to assign CString to wstring UNICODE compilation
My problem now is in actually reading in an input file using UNICODE version of everything.
I have the following code:
CString line;
// !!! Do not include newlines
while( file->ReadString( line ) ){
mSource += line;
}
Where file is CHttpFile
and mSource is wstring.
Whats happening is the input text is being cut short in this UNICODE compilation?
Any ideas whats happening here? Has been working fine.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|