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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Frnk Carleo
    New Member
    • Aug 2010
    • 1

    #1

    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

    Code:
    std::wstring strInputClaim(pstrInputClaim);
    yields this error.

    Error 2 error C2664: 'std::basic_str ing<_Elem,_Trai ts,_Ax>::basic_ string(std::bas ic_string<_Elem ,_Traits,_Ax>:: _Has_debug_it)' : cannot convert parameter 1 from 'char []' to 'std::basic_str ing<_Elem,_Trai ts,_Ax>::_Has_d ebug_it' c:\Facets\TRG_4 61\Applications \Meta\FEP\FEPAd apter\FEPAdapte rWrapperCPP2\FE PAdapterMain.cp p 46

    any help on how to convert a char array to wstring would be appreciated.
  • Oralloy
    Recognized Expert Contributor
    • Jun 2010
    • 988

    #2
    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:
    Code:
    std::wstring myne((wchar_t const*)(void const *)pstrInputClaim);

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      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.

      Comment

      Working...