i am writing a output file using ofstream in c++, file path is c:\my_folder\フォルダ\text_file.txt
but it shows Path not found, here is my code (i tried this in Visual Studio 2017 community edition)
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ofstream outfile;
outfile.open(c:\\my_folder\\フォルダ\\text_file.txt,ios::out);
if(!outfile)
{
cout<<"Path not found\n";
}
outfile << "Hello world\n";
outfile.close();
return 0;
}
and
i tried like this also refer -Displaying japanese characters in visual c++
#include <string>
#include <iostream>
#include <windows.h>
int main()
{
int codepage = CP_ACP; //CP_ACP, CP_OEMCP
int conv_codepage = CP_UTF8; //CP_UTF8
char str[256];
char str1[256];
wchar_t tstr[256], tstr2[256];
memset(str, 0x00, 256);
memset(str1, 0x00, 256);
memset(tstr, 0x00, 256);
memset(tstr2, 0x00, 256);
memcpy(str, "c:\\my_folder\\フォルダ\\text_file.txt", sizeof(str));
int nLen = MultiByteToWideChar(codepage, 0, str, -1, 0, 0);
MultiByteToWideChar(codepage, 0, str, -1, tstr, nLen);
int len = WideCharToMultiByte( conv_codepage, 0, tstr, -1, NULL, 0, 0, 0 );
WideCharToMultiByte(conv_codepage, 0, tstr, -1, str1, len ,0 ,0);
cout << "2... " << str1 << endl;
ofstream outfile;
outfile.open(str1,ios::out);
if(!outfile)
{
cout<<"Path not found\n";
}
outfile << "Hello world\n";
outfile.close();
return 0;
}
i tried using wchar_t also but none of them worked,
std::wcout.imbue(std::locale("ja_jp.utf-8"));
wchar_t c_name = L"c:\\my_folder\\フォルダ\\text_file.txt";
wofstream outfile;
outfile.open(c_name,ios::out );
if(!outfile)
{
cout<<"Path not found\n";
}
outfile << "Hello world\n";
outfile.close();
please help me.
Aucun commentaire:
Enregistrer un commentaire