当前位置:网站首页>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 :
边栏推荐
- [AI application] Hikvision ivms-4200 software installation
- flink二开,实现了个 batch lookup join(附源码)
- Approximate sum count (approximate
- [play with FPGA learning 4 in simple terms ----- talk about state machine design]
- The working day of the month is calculated from the 1st day of each month
- TIPC addressing 2
- Openmldb meetup No.4 meeting minutes
- Luogu p4281 [ahoi2008] emergency gathering / gathering (tree doubling LCA)
- [play with FPGA learning 5 in simple terms ----- reset design]
- Matlab processing of distance measurement of experimental electron microscope
猜你喜欢
VS2019代码中包含中文内容导致的编译错误和打印输出乱码问题
ImportError: cannot import name ‘Digraph‘ from ‘graphviz‘
[AGC] how to solve the problem that the local display of event analysis data is inconsistent with that in AGC panel?
Special topic of binary tree -- acwing 47 Path with a certain value in binary tree (preorder traversal)
三.芯片启动和时钟系统
TIPC addressing 2
QT学习日记8——资源文件添加
CentOS8之mysql基本用法
Special topic of binary tree -- Logu p1229 traversal problem (the number of traversals in the middle order is calculated when the pre and post order traversals of the multiplication principle are know
Special topic of binary tree -- acwing 18 Rebuild the binary tree (construct the binary tree by traversing the front and middle order)
随机推荐
[paid promotion] collection of frequently asked questions, recommended list FAQ
ImportError: cannot import name ‘Digraph‘ from ‘graphviz‘
[quick application] there are many words in the text component. How to solve the problem that the div style next to it will be stretched
STM32 single chip microcomputer programming learning
What are the software product management systems? Inventory of 12 best product management tools
mysql 基本语句
flink二开,实现了个 batch lookup join(附源码)
Flick two open, realized a batch lookup join (with source code)
ImportError: cannot import name ‘Digraph‘ from ‘graphviz‘
Binary tree topic -- p1030 [noip2001 popularization group] find the first order
启牛商学院给的股票账户安全吗?能开户吗?
函数式接口和方法引用
TIPC addressing 2
tqdm的多行显示与单行显示
Gaode draws lines according to the track
[AGC] build service 3 - authentication service example
TIPC Service and Topology Tracking4
Calculate the sum of sequences
Win11 arm system configuration Net core environment variable
QT学习日记8——资源文件添加