error in CString to const std::string conversion.
-
Hi all, i have an problem to convert a CString value in const std::string.
CString result="";
CString str="test";const std::string s = str;//here gives an error
/*
error C2440: 'initializing' : cannot convert from 'CString' to 'std::basic_string<_Elem,_Traits,_Ax>'
*/std::string s1 = fun1(s); result=s1.c\_str();
please help me for this. thanks in advance.
-
Hi all, i have an problem to convert a CString value in const std::string.
CString result="";
CString str="test";const std::string s = str;//here gives an error
/*
error C2440: 'initializing' : cannot convert from 'CString' to 'std::basic_string<_Elem,_Traits,_Ax>'
*/std::string s1 = fun1(s); result=s1.c\_str();
please help me for this. thanks in advance.
How to: Convert Between Various String Types ->[^]
"Every Little Smile can touch Somebody's Heart... May we find Hundreds of Reasons to Smile Everyday... and May WE be the Reason for someone else to smile always!" (ICAN) "Your thoughts are the architects of your destiny."
-
How to: Convert Between Various String Types ->[^]
"Every Little Smile can touch Somebody's Heart... May we find Hundreds of Reasons to Smile Everyday... and May WE be the Reason for someone else to smile always!" (ICAN) "Your thoughts are the architects of your destiny."
-
Hi all, i have an problem to convert a CString value in const std::string.
CString result="";
CString str="test";const std::string s = str;//here gives an error
/*
error C2440: 'initializing' : cannot convert from 'CString' to 'std::basic_string<_Elem,_Traits,_Ax>'
*/std::string s1 = fun1(s); result=s1.c\_str();
please help me for this. thanks in advance.
Are you building for Unicode or MBCS? I think you're building for Unicode, but are using the ANSI version of std string. Try the following:
//Unicode build
CString sz = L"Hello";
const std::wstring str = sz;//MBCS build
CStringA sz = "Hello";
const std::string str = sz;"Real men drive manual transmission" - Rajesh.
-
Are you building for Unicode or MBCS? I think you're building for Unicode, but are using the ANSI version of std string. Try the following:
//Unicode build
CString sz = L"Hello";
const std::wstring str = sz;//MBCS build
CStringA sz = "Hello";
const std::string str = sz;"Real men drive manual transmission" - Rajesh.
-
thanks but now one more error is generated
'fun1' : cannot convert parameter 1 from 'const std::wstring' to 'const std::string &'
and fun1 is like this
std::string fun1 (std::string const& s);
-
You need to be consistent in your class selections, use all unicode or all MBCS. If you are using Unicode then you need to use the
std::wstring
class rather thanstring
.The best things in life are not things.
Or use std::tstring[^] and not have to worry about it at all.
Independent ACN representative
-- Check out the possibilities for your future!
-- Financial independance
-- Full time or Part time
-- In more than 20 countries through North America, Europe, Asia and the Pacific
Within you lies the power for good - Use it!
-
Or use std::tstring[^] and not have to worry about it at all.
Independent ACN representative
-- Check out the possibilities for your future!
-- Financial independance
-- Full time or Part time
-- In more than 20 countries through North America, Europe, Asia and the Pacific
Within you lies the power for good - Use it!
PJ Arends wrote:
Or use std::tstring[^] and not have to worry about it at all.
A simple typedef, something like
#if defined(UNICODE)
typedef std::wstring STRING
#else
typedef std::string STRING
#endifwould also do it, since both are implementations of
basic_string
and its functions.The best things in life are not things.
-
Hi all, i have an problem to convert a CString value in const std::string.
CString result="";
CString str="test";const std::string s = str;//here gives an error
/*
error C2440: 'initializing' : cannot convert from 'CString' to 'std::basic_string<_Elem,_Traits,_Ax>'
*/std::string s1 = fun1(s); result=s1.c\_str();
please help me for this. thanks in advance.
Include the "atlconv.h". Then use one of the macros defined in this article http://msdn.microsoft.com/en-us/library/87zae4a3%28v=vs.80%29.aspx[^]