I want to assign a TCHAR char array to std::string in VC++ 2005, how should i do that? a simple assignment gives error i.e

TCHAR buffer[MAX-1];
std::string data;
//some operation for filling the buffer

data = buffer; //This gives error

Plz help me in doing this operation.

Re: assigning a TCHAR char array to std::string 80 80

What error do you get?

Re: assigning a TCHAR char array to std::string 80 80

UNICODE is the default setting for that compiler so if you didn't turn it off then the compiler is mapping TCHAR into wchar_t. go to Project --> Properties (bottom menu item) --> Configuration Properties --> General then change Character Set option to Not Set. If you really do want UNICODE then you have to use one of the conversion functions to convert wchar_t* to char*

Re: assigning a TCHAR char array to std::string 80 80

What error do you get?

I tried to build this code in Visual C++ 2005 and i got this error:

error C2679: binary '=' : no operator found which takes a right-hand operand of type 'TCHAR [260]' (or there is no acceptable conversion)

Re: assigning a TCHAR char array to std::string 80 80

UNICODE is the default setting for that compiler so if you didn't turn it off then the compiler is mapping TCHAR into wchar_t. go to Project --> Properties (bottom menu item) --> Configuration Properties --> General then change Character Set option to Not Set. If you really do want UNICODE then you have to use one of the conversion functions to convert wchar_t* to char*

i want to do in UNICODE only so can u suggest me those conversion functions??

Re: assigning a TCHAR char array to std::string 80 80

>error C2679: binary '=' : no operator found which takes a
>right-hand operand of type 'TCHAR [260]'
Yep, it looks like you're trying to initialize a narrow string with an array of wide characters. Try using std::wstring instead of std::string.

Re: assigning a TCHAR char array to std::string 80 80

>error C2679: binary '=' : no operator found which takes a
>right-hand operand of type 'TCHAR [260]'
Yep, it looks like you're trying to initialize a narrow string with an array of wide characters. Try using std::wstring instead of std::string.

Thanks Narue!!

Be a part of the DaniWeb community

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