473,395 Members | 1,975 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Need to convert a char array to std::wstring. How?

I am looking to convert a char array defined as
char pstrInputClaim[]

to a std::wstring

trying to use the constructor as below

Expand|Select|Wrap|Line Numbers
  1. std::wstring strInputClaim(pstrInputClaim);
  2.  
yields this error.

Error 2 error C2664: 'std::basic_string<_Elem,_Traits,_Ax>::basic_strin g(std::basic_string<_Elem,_Traits,_Ax>::_Has_debug _it)' : cannot convert parameter 1 from 'char []' to 'std::basic_string<_Elem,_Traits,_Ax>::_Has_debug_ it' c:\Facets\TRG_461\Applications\Meta\FEP\FEPAdapter \FEPAdapterWrapperCPP2\FEPAdapterMain.cpp 46

any help on how to convert a char array to wstring would be appreciated.
Aug 10 '10 #1
2 10204
Oralloy
988 Expert 512MB
What kind of data are in pstrInputClaim ?

Are they wchar_t elements, just mislabeled, or do you have to do the conversion?

If they're mislabeled, you should be able to use something like:
Expand|Select|Wrap|Line Numbers
  1. std::wstring myne((wchar_t const*)(void const *)pstrInputClaim);
Aug 10 '10 #2
weaknessforcats
9,208 Expert Mod 8TB
Try copying your wstring to an array of wchar_t using the wstring::c_str() method.

Then loop through the wchar_t array and copy the low byte to the same relative position in your char array.
Aug 11 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: red floyd | last post by:
I have a an app that I'm writing which uses char and std::string. I'm using a library which expects wchar_t arrays. Is there a standard way to convert between std::string and std::wstring, or do...
9
by: ka1cqd | last post by:
I have been looking all over the place for a method to take command line arguments and convert them to a string or wstring so i can process the data and then covert the resulting strings to...
3
by: uday.sen | last post by:
Hi, I am porting a piece of code from VC++ to linux platform. My compiler is g++ 3.2.2. I am getting following error: no matching function for call to A::setResponse(std::wstring) candidates...
8
by: Divick | last post by:
Hi all, can somebody tell how much std::wstring is supported across different compilers on different platforms? AFAIK std::string is supported by almost all C++ compilers and almost all platforms,...
14
by: rohitpatel9999 | last post by:
Hi While developing any software, developer need to think about it's possible enhancement for international usage and considering UNICODE. I have read many nice articles/items in advanced C++...
10
by: Jeffrey Walton | last post by:
Hi All, I've done a little homework (I've read responses to similar from P.J. Plauger and Dietmar Kuehl), and wanted to verify with the Group. Below is what I am performing (Stroustrup's...
1
by: Meal | last post by:
I put a chinese character into the XML file, and use const XMLCh* xvalue = personNoteNode->getFirstChild()->getNodeValue() to get the string. The begining of the string is English, and in the...
5
by: T. Crane | last post by:
Help! I am trying to figure this out, and I have the impression that it should be really easy, but I'm at a loss. Here's my problem: I want to take the output from const char *...
10
bajajv
by: bajajv | last post by:
Hi, I was trying to implement CString with std::string and std::wstring. class CString { public: std::string str; CString() {str = "ABCD";} //this works }: class CString {
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.