How to put/get INT to/from a WCHAR array ?

Posted by nimo on Stack Overflow See other posts from Stack Overflow or by nimo
Published on 2010-06-06T12:35:09Z Indexed on 2010/06/06 13:02 UTC
Read the original article Hit count: 348

Filed under:
|

how can I put a INT type variable to a wchar array ?

Thanks

EDIT:

Sorry for the short question. Yes we can cast INT to a WCHAR array using WCHAR*, but when we are retrieving back the result (WCHAR[] to INT), I just realize that we need to read size of 2 from WCHAR array since INT is 4 BYTEs which is equal to 2 WCHARs.

WCHAR arData[20];
INT iVal = 0;
wmemcpy((WCHAR*)&iVal, arData, (sizeof(INT))/2);

Is this the safest way to retrieve back INT value from WCHAR array

© Stack Overflow or respective owner

Related posts about c++

Related posts about Windows