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. 用Python绘图(数据分析与挖掘实战)

    代码1:餐饮日销额数据异常值检测(箱型图) import pandas as pd import numpy as np catering_sale = "D:\\360MoveData\\ ...

  2. Cobalt Strike 之:会话管理

    郑重声明: 本笔记编写目的只用于安全知识提升,并与更多人共享安全知识,切勿使用笔记中的技术进行违法活动,利用笔记中的技术造成的后果与作者本人无关.倡导维护网络安全人人有责,共同维护网络文明和谐. Co ...

  3. Vue 插件介绍

    功能:用于增强Vue 本质:包含install方法的一个对象,install的第一个参数是Vue,第2个以后的参数是插件使用者传递的数据. 1.定义插件: 对象.install = function( ...

  4. 退役*CPCer的找实习总结

    从2月底开始到今天,我终于拿到了第一个也是唯一一个offer(字节跳动).找实习的过程告一段落,所以想记录一下这段时间的经历. 最开始找$meopass$学长内推了小马智行,很快就接到了面试通知(再次 ...

  5. python win32 microsoft excel 类range的copyPictrue方法无效

    这个报错也是可以的,不明不白,只是提示:microsoft excel 类range的copyPictrue方法无效 网上找了好多博客,对我的情况没有效果,无奈我想打开excel看看到底是咋回事,结果 ...

  6. Mongo 常用命令

    1.登入 docker exec -it  mongo mongo  数据库 db.auth("账号","密码") docker exec -it  mongo ...

  7. 在使用IDEA提交git代码时,如何修改提交者的名字

    在Terminal终端中输入 git config user.name git config --global user.name "xl"

  8. 对Frobenius 范数的理解

    Frobenius 范数是一种矩阵范数,记为 ∣ ∣ ⋅ ∣ ∣ F ||·||_F ∣∣⋅∣∣F​,定义为一个矩阵所有元素平方和的开方,即 ∣ ∣ X ∣ ∣ F = ∑ i ∑ j x i , j ...

  9. Containerd 安装及使用(yum及源码)

    yum 安装containerd 一.下载源码库: wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker- ...

  10. flink学习总结

    flink学习总结 1.Flink是什么? Apache Flink 是一个框架和分布式处理引擎,用于处理无界和有界数据流的状态计算. 2.为什么选择Flink? 1.流数据更加真实的反映了我们的生活 ...