Wednesday, June 4, 2014

How to Convert UCHAR array to WString and String?

#include <stdio.h>
#include <windows.h>
#include <conio.h>
#include <string>

void main()
{
UCHAR s[32]="@abcdefghijklmnopqrstuvwxyz!";
char temp[32]={0};
std::wstring strws;
memcpy(&temp[0],&s[0],sizeof(s)/sizeof(UCHAR));
std::string str=temp;
    strws.assign(str.length( ),L' ' );
std::copy(str.begin( ),str.end( ),strws.begin( ));
    printf("WString equivalent of UCHAR=%ls",strws.c_str( ));
getch( );
}

No comments:

Post a Comment