方式一

void CreateAndAttachConsole() {
  if (::AllocConsole()) {
    FILE *unused;
    if (freopen_s(&unused, "CONOUT$", "w", stdout)) {
      _dup2(_fileno(stdout), 1);
    }
    if (freopen_s(&unused, "CONOUT$", "w", stderr)) {
      _dup2(_fileno(stdout), 2);
    }
    //std::ios::sync_with_stdio();
    //FlutterDesktopResyncOutputStreams();
  }
  //设置控制台编码为UTF-8
  system("CHCP 65001\n");
}

方式二

AllocConsole();
freopen("CONOUT$", "w", stdout);
//设置控制台编码为UTF-8
  system("CHCP 65001\n");

发表评论

邮箱地址不会被公开。 必填项已用*标注