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 ...
随机推荐
- 有趣的python库-MyQR
MyQR-个性二维码 基本使用 from MyQR import myqr import os myqr.run( words="hu qing nian ni zhen bang, you ...
- CentOS7一键安装RPM版LNMP(NGINX+PHP+MySQL)环境
转载:简书 CentOS7一键安装RPM版LNMP(NGINX+PHP+MySQL)环境 - 简书 (jianshu.com) (需要配置nginx.conf文件) 转载:csdn (35条消息) V ...
- C# 通过反射获取类字段名和值并加入到字典中(包含递归获取)
//测试类 public class HKAddvisitor1{ public string code { set; get; } public string msg { set; ge ...
- vue的数据更新视图不同步的处理用Vue.$set()
// vue的数据更新视图不同步的处理用Vue.$set() // 通过Vue.set方法设置data属性vm.$set(最终值,数组索引,数组值) ==Vue.$set(arr,index,val) ...
- Angular UI库
1.angular 使用 bootstrap 安装bootstrap npm install bootstrap --save 安装bootstrap-icons npm i bootstrap-ic ...
- Django中admin的一些知识点
Django中的Admin站点管理: 内容发布的部分由网站的管理员负责,包括查看.添加.修改.删除数据: Django项目中默认启用Admin管理站点:列表页选项, 编辑页选项, 重写模板. #准备工 ...
- TCP怎样保证可靠传输
TCP的可靠性保证 TCP主要提供了检验和,序列号/确认应答,超时重传,最大消息长度,滑动窗口控制等方法实现了可靠性传输. 检验和 通过检验和的方式,接收端可以检测出来数据是否有差错和异常,假如有差错 ...
- Kotlin学习-函数(表达式,lambda,高阶函数)
Kotlin中函数 3种表达形式: 一般函数: fun sum(a: Int, b: Int): Int { return a+b } 简化函数为表达式形式: fun sum2(a: Int, b: ...
- SAP 登录文件路径
链接文件地址C:\Users\Administrator\AppData\Roaming\SAP\Common 复制:Common文件夹所有文件替换
- Vue 项目中实现的微信、微博、QQ空间分享功能(亲测有效)
需求:文章添加分享功能(包括微信.微博.QQ空间) 如下图所示: 点击图标分别跳转到如下界面:(实现效果如下) 话不多说直接代码(可以封装成组件) <template> <div c ...