User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 456,494 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,692 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 7354 | Replies: 6
Reply
Join Date: Aug 2007
Posts: 18
Reputation: Ashu@sym is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Ashu@sym Ashu@sym is offline Offline
Newbie Poster

Help assigning a TCHAR char array to std::string

  #1  
Sep 20th, 2007
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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2004
Posts: 6,515
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 31
Solved Threads: 489
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

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

  #2  
Sep 20th, 2007
What error do you get?
I'm here to prove you wrong.
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,541
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 40
Solved Threads: 972
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

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

  #3  
Sep 20th, 2007
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*
Last edited by Ancient Dragon : Sep 20th, 2007 at 9:41 am.
<<Freelance Programmer>> << Hobby Site>>
Signature links for sale. PM me for details
Reply With Quote  
Join Date: Aug 2007
Posts: 18
Reputation: Ashu@sym is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Ashu@sym Ashu@sym is offline Offline
Newbie Poster

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

  #4  
Sep 20th, 2007
Originally Posted by Narue View Post
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)
Reply With Quote  
Join Date: Aug 2007
Posts: 18
Reputation: Ashu@sym is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Ashu@sym Ashu@sym is offline Offline
Newbie Poster

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

  #5  
Sep 20th, 2007
Originally Posted by Ancient Dragon View Post
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??
Reply With Quote  
Join Date: Sep 2004
Posts: 6,515
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 31
Solved Threads: 489
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

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

  #6  
Sep 20th, 2007
>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.
I'm here to prove you wrong.
Reply With Quote  
Join Date: Aug 2007
Posts: 18
Reputation: Ashu@sym is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Ashu@sym Ashu@sym is offline Offline
Newbie Poster

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

  #7  
Sep 21st, 2007
Originally Posted by Narue View Post
>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!!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 3:24 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC