Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
372 views
in Technique[技术] by (71.8m points)

c++ - _O_WTEXT, _O_U16TEXT, _O_U8TEXT - are these modes possible in mingw compiler, are there any workarounds?

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

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

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

Is this a show-stopper with this compiler ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...