Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/149.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;std::wofstream unicode问题。_C++_Unicode_Wofstream - Fatal编程技术网

C++ C++;std::wofstream unicode问题。

C++ C++;std::wofstream unicode问题。,c++,unicode,wofstream,C++,Unicode,Wofstream,我使用VS 2012编写了以下代码: std::wofstream logout("my_log.txt", std::ios_base::out | std::ios_base::trunc); std::locale utf8_locale(locale(), new codecvt_utf8<wchar_t>); logout.imbue(utf8_locale); if (!logout.is_open()) { printf("Cannot open file.\n"

我使用VS 2012编写了以下代码:

std::wofstream logout("my_log.txt", std::ios_base::out | std::ios_base::trunc);
std::locale utf8_locale(locale(), new codecvt_utf8<wchar_t>);
logout.imbue(utf8_locale);

if (!logout.is_open()) 
{
 printf("Cannot open file.\n"); 
 return 1; 
}
else printf("Log file created.\n");

logout << "Client IP            │"<< "Recv time                │"<< "Request               │"<< "Response     "<<endl;
logout << "─────────────────────┼"<< "─────────────────────────┼"<<endl;
std::wofstream注销(“my_log.txt”,std::ios_base::out | std::ios_base::trunc);
std::locale utf8\u locale(locale(),新编码vt\u utf8);
注销。插入(utf8_区域设置);
如果(!logout.is_open())
{
printf(“无法打开文件。\n”);
返回1;
}
else printf(“已创建日志文件。\n”);

注销这就是为什么我们在字符串文本中只使用ASCII

您的代码很好,但字符串文本显然不包含您认为它们的功能。这可能是由于配置错误或功能不足的文本编辑器造成的


改用转义序列(
\uxxx
),这样你就知道你得到了什么。2015年,使用ASCII字符形成的源代码不会出错。

这就是为什么我们在字符串文本中只使用ASCII

您的代码很好,但字符串文本显然不包含您认为它们的功能。这可能是由于配置错误或功能不足的文本编辑器造成的


改用转义序列(
\uxxx
),这样你就知道你得到了什么。在2015年,用ASCII字符形成的源代码不会出错。

哦,这真是太有趣了

wchar_t *s1 = L"\u2502"; // "│"
wchar_t *s2 = L"\u2500"; // "─"
wchar_t *s3 = L"\u253C"; // "┼"
logout << s1<<s2<<s3<<endl;

这也行。

哦,这真是太有趣了

wchar_t *s1 = L"\u2502"; // "│"
wchar_t *s2 = L"\u2500"; // "─"
wchar_t *s3 = L"\u253C"; // "┼"
logout << s1<<s2<<s3<<endl;

这同样有效。

你确定你用来查看文件的编辑器支持UTF8/是在unicode模式下吗?嗯,实际上我不确定。我曾尝试使用MS Word和记事本打开此文件,但问题仍然存在。没有MS产品支持UTF8。所有MS/Windows均为UTF16。尝试使用十六进制查看器查看文件中的实际内容。@RichardCriten我文件中的所有unicode符号都以十六进制格式显示为3F。您确定用于查看文件的编辑器支持UTF8/处于unicode模式吗?嗯,实际上我不确定。我曾尝试使用MS Word和记事本打开此文件,但问题仍然存在。没有MS产品支持UTF8。所有MS/Windows均为UTF16。尝试使用十六进制查看器查看文件中的实际内容。@RichardCriten我的文件中的所有unicode符号都以十六进制格式显示为3F。建议:
wchar\u t const s1=L'\u2502'。这些非ASCII文本几乎肯定无法与GCC一起使用。建议:
wchar_t const s1=L'\u2502'。这些非ASCII文本几乎肯定无法与GCC一起使用。它是不可携带的。