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

查看:1035
本文介绍了_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\x043a\x043e\x0448\x043a\x0430 \x65e5\x672c\x56fd\\\
);
return 0;
}

在编译时返回错误: _O_U16TEXT未声明这个范围

解决方案

好吧,有一个简单的解决方法:只使用这些常量的值,而不是他们的名字。例如, _O_U16TEXT 0x00020000 _O_U8TEXT 0x00040000



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

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

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


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

int main(void) {
  _setmode(_fileno(stdout), _O_U16TEXT);
  wprintf(L"\x043a\x043e\x0448\x043a\x0430 \x65e5\x672c\x56fd\n");
  return 0;
}

returns error at compilation: _O_U16TEXT was not declared in this scope

Is this a show-stopper with this compiler ?

解决方案

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.

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"Русский текст\n";
}

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

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