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的更多相关文章

  1. windows console Kill PID 端口查看

    开始--运行--cmd 进入命令提示符 输入netstat -ano 即可看到所有连接的PID 之后在任务管理器中找到这个PID所对应的程序如果任务管理器中没有PID这一项,可以在任务管理器中选&qu ...

  2. [分享] Code::Blocks Windows Console 中文亂碼解決

    相信各位大大們應該都有聽過Code::Blocks這個IDE,但網路上有許多人反應Code::Blocks不能編出中文的Console程式,但 Code::Blocks最新的版本預設使用UTF-8做為 ...

  3. 在C#中,Windows Console控制台 设置控制台标题、禁用关闭按钮、关闭快速编辑模式、插入模式

    设置控制台标题 禁用关闭按钮 关闭快速编辑模式 关闭插入模式 设置控制台标题.禁用关闭按钮 #region 设置控制台标题 禁用关闭按钮 [DllImport("user32.dll&quo ...

  4. windows console 控制台自启动

    var fileName = Assembly.GetExecutingAssembly().Location; System.Diagnostics.Process.Start(fileName);

  5. Git for Windows v2.11.0 Release Notes

    homepage faq contribute bugs questions Git for Windows v2.11.0 Release Notes Latest update: December ...

  6. 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.  ...

  7. Professional C# 6 and .NET Core 1.0 - Chapter 39 Windows Services

    本文内容为转载,供学习研究.如有侵权,请联系作者删除. 转载请注明本文出处:Professional C# 6 and .NET Core 1.0 - Chapter 39 Windows Servi ...

  8. 环境搭建文档——Windows下的Git搭建详解

    Git是一个开源的分布式版本控制系统,可以有效.高速的处理从很小到非常大的项目版本管理.具体安装步骤如下: 第一步:先从官网下载最新版本的Git 官网地址:https://git-scm.com/do ...

  9. 在 windows 上安装 git 2.22

    下载 by win 下载地址:https://git-scm.com/download/win 如下图.选择对应的版本下载: 安装 by win 1.双击下载好的git安装包.弹出提示框.如下图: 2 ...

  10. 在 windows 上安装 git 2.15

    下载 by win 下载地址:https://git-scm.com/download/win 如下图.选择对应的版本下载: 安装 by win 1.双击下载好的git安装包.弹出提示框.如下图: 2 ...

随机推荐

  1. 推荐一个分布式单点登录框架XXL-SSO!

    有关单点登录(SSO)之前有写过两篇文章 一文读懂 JWT! 看完这篇不能再说不懂SSO原理了! 如果说XXL-JOB你可能并不陌生,它是非常火爆的一个分布式任务调度平台.但其实在该作者还有一个非常优 ...

  2. [代码审计基础 02]-SQL注入和预编译和预编译绕过

    SQL注入 thinkphp基本没得SQL注入,除非魔改 ORM框架的错误使用 一个专门用来防御SQL注入的框架 错误写法-java/mybatis <select id = "fin ...

  3. JZOJ 3447.摘取作物

    \(\text{Problem}\) 在一个矩阵里选数,每行最多选两个,每列最多选两个,最大会价值 \(n,m \le 30\) \(\text{Analysis}\) 对个这个限制如何实现? 跑费用 ...

  4. 轻量级CI/CD发布部署环境搭建及使用_01_基本介绍

    轻量级CI/CD发布部署环境搭建及使用_01_基本介绍 授人以鱼不如授人以渔,如果说的别人都没明白,说明自己实际也不是太明白 最终实现效果如图 1,选择相应环境下的项目,执行构建 注: web:vue ...

  5. 05for循环

    for循环 循环的作用与分类 作用:让代码更加高效的重复运行 分类:for循环和while循环 for循环结构 for 临时变量 in 可迭代对象: 重复执行的代码1 重复执行的代码2 ... 可迭代 ...

  6. python如何画高光谱立体图像

    语句含义:spectral.view_cube(image,bands=[29,19,9])  中的29,19和9是第几个波段,可以改成数据波段数以内的其他的数值

  7. 安装pytorch报错 ERROR: Could not install packages due to an OSError: [Errno 28] No space left on device

    windos安装,报错如下 看了不少回答,大概是缓存和内存满了 我的C盘只给了70G,然后意外发现只剩下3G多了,先用系统自带的清理工具清理了一下,然后腾讯电脑管家"工具箱"中的& ...

  8. Android悬浮窗全屏不获取焦点但是可以漏出软键盘的办法

    addFlags( WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);的作用是在不获取焦点的时候显示软键盘. 接触这个标记 getWindow().c ...

  9. 异常:java.sql.SQLException: HOUR_OF_DAY: 0 -> 1解决

    问题:Error attempting to get column 'xxTime' from result set. Cause: java.sql.SQLException: HOUR_OF_DA ...

  10. UVM——通过一个简单的testbench来了解UVM组件的phase执行顺序

    先写好一个top.sv 查看代码 // 导入VCS或者Modelsim自带的UVM库和宏 `include "uvm_macros.svh" import uvm_pkg::*; ...