相关疑难解决方法(0)

如何在Windows命令行中使用unicode字符?

我们在Team Foundation Server(TFS)中有一个项目,其中包含非英语字符(š).当我试图编写一些与构建相关的东西时,我们偶然发现了一个问题 - 我们无法将š字母传递给命令行工具.命令提示符或其他什么不是搞砸了,并且tf.exe实用程序找不到指定的项目.

我已经尝试了.bat文件的不同格式(ANSI,带有和不带BOM的 UTF-8 )以及用JavaScript编写脚本(这本身就是Unicode) - 但没有运气.如何执行程序并将其传递给Unicode命令行?

unicode command-line input windows-console

299
推荐指数
12
解决办法
40万
查看次数

在Windows控制台应用程序中输出unicode字符串

嗨,我试图将unicode字符串输出到带有iostreams的控制台并失败.

我发现了这一点: 在c ++控制台应用程序中使用unicode字体 ,这个代码片段有效.

SetConsoleOutputCP(CP_UTF8);
wchar_t s[] = L"èéøÞ????æ?a";
int bufferSize = WideCharToMultiByte(CP_UTF8, 0, s, -1, NULL, 0, NULL, NULL);
char* m = new char[bufferSize]; 
WideCharToMultiByte(CP_UTF8, 0, s, -1, m, bufferSize, NULL, NULL);
wprintf(L"%S", m);
Run Code Online (Sandbox Code Playgroud)

但是,我没有找到任何方法来使用iostream正确输出unicode.有什么建议?

这不起作用:

SetConsoleOutputCP(CP_UTF8);
utf8_locale = locale(old_locale,new boost::program_options::detail::utf8_codecvt_facet());
wcout.imbue(utf8_locale);
wcout << L"¡Hola!" << endl;
Run Code Online (Sandbox Code Playgroud)

编辑 我找不到任何其他解决方案,而不是在流中包装此片段.希望,有人有更好的想法.

//Unicode output for a Windows console 
ostream &operator-(ostream &stream, const wchar_t *s) 
{ 
    int bufSize = WideCharToMultiByte(CP_UTF8, 0, s, -1, NULL, 0, NULL, NULL);
    char *buf = …
Run Code Online (Sandbox Code Playgroud)

c++ unicode iostream windows-console

68
推荐指数
4
解决办法
6万
查看次数

标签 统计

unicode ×2

windows-console ×2

c++ ×1

command-line ×1

input ×1

iostream ×1