Skip to main content
daitranthanhoa
Inspiring
April 6, 2022
Question

How can output filename include UTF8 Text?

  • April 6, 2022
  • 1 reply
  • 409 views

My code output text to 1 file:

If FileName not include UTF8 Text (Ex: 1.html), it output OK,

But FileName include UTF8 Text  (Ex: 名称未設定-1.indd_1.html), it can't create file.

How can output filename include UTF8 Text?

 

WideString strContent=WideString("test名称未設定");

PMString filename="C:/Users/pc1/Desktop/cc/名称未設定-1.indd_1.html";

std::string utf8StdStr;
StringUtils::ConvertWideStringToUTF8(strContent, utf8StdStr);

std::string strfile;
StringUtils::ConvertWideStringToUTF8(WideString(filename), strfile);

std::ofstream fileOut(strfile);

if (!fileOut)
{
ASSERT_FAIL("ofstream failed.");
break;
}
fileOut << utf8StdStr;
fileOut.close();

This topic has been closed for replies.

1 reply

Olivier Beltrami
Legend
April 6, 2022

Hello,

Shouldn't your filename be

"C:\\Users\\pc1\\Desktop\\cc\\名称未設定-1.indd_1.html"

instead ?

Also, did you try saving to a basic folder, in case there are user rights permissions issues with saving to the desktop ?

Very best regards,

Olivier

daitranthanhoa
Inspiring
April 6, 2022

It can create file, but filename output not correct:

Input: 名称未設定-1.indd_1.html

Output: ヨシマ誇「ム旁ィ-1.indd_1.html

Olivier Beltrami
Legend
April 6, 2022

Try pre-pending it with L.

L"C:\\Users\\pc1\\Desktop\\cc\\名称未設定-1.indd_1.html"