Basically, you need to use all the functions associated with Wide-characters in C. It's been a resurgent topic to me, to be able to output into stream and files Japanese characters.
In this case, I have myself tested that it actually works.
If you don't know exactly what you are doing, ask me, since I can provide you with the necessary material for the task.
First, you'll declare a variable
wchar_t jpSentence[100] = L"今はVisualC++2010を試みていますよ。";
It is compulsory to say that "TCHAR" and "wchar_t" are the same types only if "_UNICODE" macro has been set and your projects files are in saved in UNICODE.
Once done this you have to open the file:
FILE *fp = _wfopen(L"japfile.txt", L"w, ccs=UTF-8");
We create a pointer to a FILE. Then we open it with "_wfopen" (which is the correspondent function to open wide character fies) and we use the arguments
"japfile.txt" (in my case is the filename I wish to write into).
Then on the second argument I specify two things the mode:
The first one, is that I want to write, "w".
The second one, is that I want to specify the encoding (ccs) of file the file to be saved as "UTF-8".
If you do omit this last step, when you open your notepad you'll see "?" on positions
where Japanese characters are located. So it is very important. Since the file will be written as ANSI.
Note: Just for you to know (If you didn't know) the "L" stuck right at the left of wide-character strings has to be put in order to make the compiler you are completely conscious that you are using a wide-character string. If you wish to compile your project as both UNICODE and ANSI (that is making two different executable versions) use the TEXT("") macro. Depending if the _UNICODE macro has been defined or not, all TCHAR will be either "char" or "wchar_t" and your strings will be prefixed with the "L" automatically when the TEXT() macro encountered.
Finally,
fwprintf(fp,L"%ls",jpSentence);
fclose(fp);
You can see that "fwprintf" stands for "File Wide PRINT Function".
The second argument has to be specified as "%ls", meaning "long string".
Finally that's all for now.
I really encourage you to take a deeper look into these webpage references to understand more how it works and what other functions you can use:
http://www.cplusplus.com/reference/cwchar/[
^]
http://publib.boulder.ibm.com/infocenter/iseries/v7r1m0/index.jsp?topic=%2Frtref%2Ffwprintf.htm[
^]
and
http://msdn.microsoft.com/es-es/library/yeby3zcb%28v=vs.80%29.aspx[
^]
P.S: For your directory problem, you should do something like:
FILE *fp = _wfopen(L"幹事の方/japfile.txt", L"w, ccs=UTF-8");
FILE *fp = _wfopen(L"幹事の方/japfile.txt", L"w, ccs=UTF-8");
The final code should look like this:
#include <Windows.h>
#include <wchar.h> // Include only if you are not using Windows.h
#include <stdio.h>
FILE *fp = _wfopen(L"幹事の方/japfile.txt", L"w, ccs=UTF-8");
if(!fp)
{
exit(EXIT_FAILURE);
}
wchar_t jpSentence[100] = L"今はVisualC++2010を試みていますよ。";
fwprintf(fp,L"%ls",jpSentence);
fclose(fp);
exit(EXIT_SUCCESS);