当前位置:网站首页>Compilation errors and printout garbled problems caused by Chinese content in vs2019 code
Compilation errors and printout garbled problems caused by Chinese content in vs2019 code
2022-07-02 11:17:00 【System_ sleep】
Preface
stay VS2019 in , If the code contains Chinese string definitions or comments , It will lead to all kinds of inexplicable compilation errors , Even if you are lucky , There is no error in compilation , You will also encounter the problem of printing Chinese garbled codes on the console , It makes people feel irritable .
Compilation problems
1. Chinese string constants are defined in the code, resulting in compilation errors :“ Line breaks in constants “ ;
2. The code contains Chinese comments, which leads to compilation errors : Can't find XXX ( macro 、 Variable )、XXX Is not a constant / Variables and other problems caused by missing declarations ;
The problem of printing garbled code
Code print Chinese string , The output at the command prompt is garbled ;
resolvent , Choose one of the three methods :
One . Modify the code file format to utf-8 Signed , Give Way MSVC The compiler can automatically recognize and utf-8 BOM Format load file :
- Use an external editor to save the code file as utf8-BOM Format ;
- or Open the code file , stay VS2019 “ Advanced save options ” Select the code file saving format as “Unicode- Signed “;
Two . Change the code format :
Modify Chinese string 、 Format of Chinese Notes , Add English space at the end of Chinese , Give Way MSVC The compiler can use GBK Code loading and compiling Chinese utf-8 Encoded string , It can solve the problem of compilation errors , Print or garbled ;
3、 ... and . Force the designation of MSVC The encoding format of the code file loaded by the compiler :
- stay VS2019“ project ”-“ Engineering properties ” Dialog box -“C/C++”-“ All options " Subpage , stay “ Additional options ” Add in “/utf-8” ( Equate to ”/source-charset:utf-8 /execution-charset:utf-8");
- stay VS2019“ project ”-“ Engineering properties ” Dialog box -“C/C++”-" All options " Subpage , stay “ Additional options ” Add in “/source-charset:utf-8 /execution-charset:gbk” ( The former represents the encoding of the file itself , The latter indicates the encoding of bytes in the compiled character array );
summary :
1. If it's a new project , Recommended method 1 , Let all new code files be unified as utf-8 BOM Format ;
2. If it is cross platform code , And the document contains a small amount of Chinese Notes , You can try method 2 ;
3. If it is an existing historical complex project ( Solutions that are not exported using tools ), You can try method 3 , But you need to pay attention to the settings execution-charset when , Consider at the same time UI Requirements for string encoding of both display and print ( It may not be the same );
reference information :
边栏推荐
- Win11 arm system configuration Net core environment variable
- Rest (XOR) position and thinking
- CentOS8之mysql基本用法
- Openmldb meetup No.4 meeting minutes
- Use Huawei performance management service to configure the sampling rate on demand
- 二.Stm32f407芯片GPIO编程,寄存器操作,库函数操作和位段操作
- mmrotate旋转目标检测框架使用记录
- 【深入浅出玩转FPGA学习2----设计技巧(基本语法)】
- QT learning diary 7 - qmainwindow
- [AI application] Hikvision ivms-4200 software installation
猜你喜欢

C#多维数组的属性获取方法及操作注意

PowerBI中导出数据方法汇总

What are the software product management systems? Inventory of 12 best product management tools

数字化转型挂帅复产复工,线上线下全融合重建商业逻辑

I STM32 development environment, keil5/mdk5.14 installation tutorial (with download link)

八大排序汇总

TIPC Service and Topology Tracking4
![[AGC] how to solve the problem that the local display of event analysis data is inconsistent with that in AGC panel?](/img/66/674a06d8e45a31ae879b81554ef373.png)
[AGC] how to solve the problem that the local display of event analysis data is inconsistent with that in AGC panel?

How to implement tabbar title bar with list component

QT学习日记7——QMainWindow
随机推荐
How to implement tabbar title bar with list component
V2x SIM dataset (Shanghai Jiaotong University & New York University)
Implementation of six singleton modes
Static variables in static function
Openmldb meetup No.4 meeting minutes
数字化转型挂帅复产复工,线上线下全融合重建商业逻辑
Functional interfaces and method references
Resources读取2d纹理 转换为png格式
ROS lacks xacro package
TIPC Cluster5
liftOver进行基因组坐标转换
Gaode draws lines according to the track
One trick to quickly realize custom application titlebar
C# 文件与文件夹操作
Binary tree topic -- Luogu p3884 [jloi2009] binary tree problem (DFS for binary tree depth BFS for binary tree width Dijkstra for shortest path)
从攻击面视角,看信创零信任方案实践
Verilog 和VHDL有符号数和无符号数相关运算
【云原生】2.5 Kubernetes 核心实战(下)
TIPC Getting Started6
每月1号开始计算当月工作日

