about wide character:
First try to understand how data is stored in a wchar_t variable. Its a two byte length. To accommodate old ascii data the sequence is like below:
wchar_t a;
a='A'; a=L'A';
According to your code it will stop writing when it gets a null character. and variable
a holds a null character in the first byte.
either of two things
1. Use a class which is capable of writing wide string
or
2. I dont know c++. but using stdin function where file must have to be open as binary. and you can do your writing without trouble
[Edit]Correcting Sequence[/Edit]
Also Debug the code below:
int _tmain(int argc, _TCHAR* argv[])
{
wchar_t a[3]=L"ab";
char *b;
b=(char*)(a);
return 0;
}
if you debug you would see the stored character sequence is like below:
b[0]='a'
b[1]=0
b[2]='b'
b[3]=0
b[4]=0
b[5]=0
if you try to write the above string in a file using the class you have stated then you will get only "a" in the file. because in the second byte its getting string terminating character.
Note: for wide character string terminating character is sequence of two null value. but of course array[even_index] and array[even_index+1], not array[odd_index] and array[odd_index+1]. as example array[0] and array[1] but not array[1] and array[2]. here array is single byte string