how to make the windows console works with utf-8 encoded project
the console of the windows os is not working in the utf-8 encoding, by default. When you force your code be encoded with utf-8, the console will not print what you want.
Here is how to configure your project encoding with utf-8, and work as it is in windows.
configure visual sutdio to encoding with utf-8
add a .editorconfig file to you project. visual studio will use the encoding as the configuration file asked.

put the code in the .editorconfig
# Rules in this file were initially inferred by Visual Studio IntelliCode from the D:\data\playGround\playGround_y9kp\playGround_y9kp\ codebase based on best match to current usage at 2022/8/27
# You can modify the rules from these initially generated values to suit your own policies
# You can learn more about editorconfig here: https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference
# [*.cs]
[*.{js,py,cpp, hpp, c, h}]
charset = utf-8
set your project build and execute in utf-8
this will be configured in the project property page.

tell the working encoding at the very beginning of you code
method 0
int main(int argc, char** argv)
{
system("chcp 65001"); // set the console work with utf-8 encoding.
cout << "aaaaaaaaaa" << endl;
cout << "噫吁戏危乎高哉" << endl;
cout << "aaaaaaaaaa" << endl;
return 0;
}
method 1
use the gragma
#pragma execution_character_set("utf-8")
int main(int argc, char** argv)
{
cout << "aaaaaaaaaa" << endl;
cout << "噫吁戏危乎高哉" << endl;
cout << "aaaaaaaaaa" << endl;
return 0;
}
start to run you code and check the result

reference
c++ - Is there an easy way to write UTF-8 octets in Visual Studio? - Stack Overflow
https://stackoverflow.com/questions/19987448/is-there-an-easy-way-to-write-utf-8-octets-in-visual-studio
(118条消息) #pragma execution_character_set解决中文乱码_lyingcloud的博客-CSDN博客_execution_character_set
https://blog.csdn.net/chenhongwei610/article/details/101512960
execution_character_set pragma | Microsoft Docs
https://docs.microsoft.com/en-us/cpp/preprocessor/execution-character-set?view=msvc-170
/utf-8 (Set source and execution character sets to UTF-8) | Microsoft Docs
https://docs.microsoft.com/en-us/cpp/build/reference/utf-8-set-source-and-executable-character-sets-to-utf-8?view=msvc-170
how to make the windows console works with utf-8 encoded project的更多相关文章
- windows console Kill PID 端口查看
开始--运行--cmd 进入命令提示符 输入netstat -ano 即可看到所有连接的PID 之后在任务管理器中找到这个PID所对应的程序如果任务管理器中没有PID这一项,可以在任务管理器中选&qu ...
- [分享] Code::Blocks Windows Console 中文亂碼解決
相信各位大大們應該都有聽過Code::Blocks這個IDE,但網路上有許多人反應Code::Blocks不能編出中文的Console程式,但 Code::Blocks最新的版本預設使用UTF-8做為 ...
- 在C#中,Windows Console控制台 设置控制台标题、禁用关闭按钮、关闭快速编辑模式、插入模式
设置控制台标题 禁用关闭按钮 关闭快速编辑模式 关闭插入模式 设置控制台标题.禁用关闭按钮 #region 设置控制台标题 禁用关闭按钮 [DllImport("user32.dll&quo ...
- windows console 控制台自启动
var fileName = Assembly.GetExecutingAssembly().Location; System.Diagnostics.Process.Start(fileName);
- Git for Windows v2.11.0 Release Notes
homepage faq contribute bugs questions Git for Windows v2.11.0 Release Notes Latest update: December ...
- Scott Hanselman's 2014 Ultimate Developer and Power Users Tool List for Windows -摘自网络
Everyone collects utilities, and most folks have a list of a few that they feel are indispensable. ...
- Professional C# 6 and .NET Core 1.0 - Chapter 39 Windows Services
本文内容为转载,供学习研究.如有侵权,请联系作者删除. 转载请注明本文出处:Professional C# 6 and .NET Core 1.0 - Chapter 39 Windows Servi ...
- 环境搭建文档——Windows下的Git搭建详解
Git是一个开源的分布式版本控制系统,可以有效.高速的处理从很小到非常大的项目版本管理.具体安装步骤如下: 第一步:先从官网下载最新版本的Git 官网地址:https://git-scm.com/do ...
- 在 windows 上安装 git 2.22
下载 by win 下载地址:https://git-scm.com/download/win 如下图.选择对应的版本下载: 安装 by win 1.双击下载好的git安装包.弹出提示框.如下图: 2 ...
- 在 windows 上安装 git 2.15
下载 by win 下载地址:https://git-scm.com/download/win 如下图.选择对应的版本下载: 安装 by win 1.双击下载好的git安装包.弹出提示框.如下图: 2 ...
随机推荐
- 消息传递(news)题解
代码 #include<cstdio> #include<algorithm> using namespace std; const int N = 200000; int f ...
- 如何在js中把对象object追加到数组中?
arrObj 是array类型,如何追加数据? var arrObj =[] for(var i = 0;i<2;i++){ var obj = {} obj.ass_head_img = ' ...
- WPF Xaml标签的一些特殊符号 如何输入
小于号 < 输入 < 注意有分号 大于号 > 输入 > 符号 & 输入 & 引号 " 输入 "
- 基于Python的OpenGL 01 之Hello Triangle
1. 引言 本文基于Python语言,描述OpenGL的绘制流程,这里描述的是OpenGL的核心模式(Core-profile) 本文基于GLFW与PyOpenGL库进行开发,Python语言下的Op ...
- 【深入浅出 Yarn 架构与实现】4-6 RM 行为探究 - 申请与分配 Container
本小节介绍应用程序的 ApplicationMaster 在 NodeManager 成功启动并向 ResourceManager 注册后,向 ResourceManager 请求资源(Contain ...
- LeetCode-1765 地图中的最高点
来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/map-of-highest-peak 题目描述 给你一个大小为 m x n 的整数矩阵 isWa ...
- pytho获取C函数返回值
python调用C语言接口 注:本文所有示例介绍基于linux平台 在底层开发中,一般是使用C或者C++,但是有时候为了开发效率或者在写测试脚本的时候,会经常使用到python,所以这就涉及到一个问题 ...
- postman 使用简单汇总
postman官网下载地址:https://www.postman.com/downloads/ Postman支持功能 1.快速构建 2.参数化与变量设置提取 3.查看请求数据 4.提供断言功能 5 ...
- kvm 透传显卡至win10虚拟机
环境 已安装nvidia 显卡 驱动 操作系统:CentOS Linux release 7.9.2009 (Core) 内核版本:Linux 5.4.135-1.el7.elrepo.x86_64 ...
- vue项目引入外部UI,不同页面自定义不同样式
做项目有些需求是项目要改版,但是又想留一个老项目的入口,所以不同页面要用不同样式,对于引入外部UI来说是个麻烦事,因为要设置外部UI组件的样式必须是全局设置,也就是说<style>< ...