_O_WTEXT、_O_U16TEXT、_O_U8TEXT - 这些模式在 mingw 编译器中是否可行,是否有任何解决方法? [英] _O_WTEXT, _O_U16TEXT, _O_U8TEXT - are these modes possible in mingw compiler, are there any workarounds?

查看:16
本文介绍了_O_WTEXT、_O_U16TEXT、_O_U8TEXT - 这些模式在 mingw 编译器中是否可行,是否有任何解决方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <fcntl.h>
#include <io.h>
#include <stdio.h>

int main(void) {
  _setmode(_fileno(stdout), _O_U16TEXT);
  wprintf(L"x043ax043ex0448x043ax0430 x65e5x672cx56fd
");
  return 0;
}

编译时返回错误:_O_U16TEXT 未在此范围内声明

这是这个编译器的亮点吗?

Is this a show-stopper with this compiler ?

推荐答案

好吧,有一个简单的解决方法:只需使用这些常量的值而不是它们的名称.例如,_O_U16TEXT0x00020000_O_U8TEXT0x00040000.

Well, there's a simple workaround: just use values of these constants instead of their names. For example, _O_U16TEXT is 0x00020000 and _O_U8TEXT is 0x00040000.

我刚刚确认它可以在 Windows 10 上使用 g++ 4.8.1 与 _setmode 一起使用:

I've just confirmed that it works with _setmode using g++ 4.8.1 on Windows 10:

#include <iostream>
#include <fcntl.h>
#include <io.h>
#include <stdio.h>

int main() {
    _setmode(_fileno(stdout), 0x00020000); // _O_U16TEXT
    std::wcout << L"Русский текст
";
}

这篇关于_O_WTEXT、_O_U16TEXT、_O_U8TEXT - 这些模式在 mingw 编译器中是否可行,是否有任何解决方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆