当前位置:网站首页>解决【命令行/终端】颜色输出问题
解决【命令行/终端】颜色输出问题
2022-08-05 10:27:00 【SN-Grotesque】
前言
通常我们在想让终端输出颜色的时候会使用到颜色代码,比如\x1b[31m,但是在Windows系统中不管使用哪一种语言来输出这个颜色代码,可能最终都会变成乱码。
有的人的Windows系统可能不会出现这个问题,但如果你接触的系统多一些就会明白这个问题产生的原因。
在Linux系统中,是从未出现过这种问题的,为什么?
因为Linux默认使用的是UTF-8编码,而绝大多数Windows系统使用的是GB系列的编码比如GBK,GB2312,GB18030。
编码不同也就导致了输出的结果不同。
解决
在代码的开头执行一遍代码页编号修改,以下使用C语言与Python举例
#include <stdlib.h> // 这一个头文件是必须的
int main(int argc, char **argv)
{
system("chcp 65001"); // 修改为UTF-8编码
... // 你的其他代码
}
from os import system
system("chcp 65001")
... # 你的其他代码
边栏推荐
- 气象数据数据处理实例——matlab字符串切割匹配与R语言日期匹配(数据拼接)
- 用KUSTO查询语句(KQL)在Azure Data Explorer Database上查询LOG实战
- Login function and logout function (St. Regis Takeaway)
- 化繁为简!阿里新产亿级流量系统设计核心原理高级笔记(终极版)
- 19.3 restart the Oracle environment
- MySQL transactions
- Complete image segmentation efficiently based on MindSpore and realize Dice!
- In-depth understanding of timeout settings for Istio traffic management
- 如何选币与确定对应策略研究
- 你最隐秘的性格在哪?
猜你喜欢

【综合类型第 35 篇】程序员的七夕浪漫时刻

华为轻量级神经网络架构GhostNet再升级,GPU上大显身手的G-GhostNet(IJCV22)

Meteorological data processing example - matlab string cutting matching and R language date matching (data splicing)

数据可视化(二)

Jenkins manual (2) - software configuration

什么是 DevOps?看这一篇就够了!

【 temperature warning program DE development 】 event driven model instance

Microcontroller: temperature control DS18B20

电竞、便捷、高效、安全,盘点OriginOS功能的关键词

Confessing in the era of digital transformation: Mai Cong Software allows enterprises to use data in the easiest way
随机推荐
LeetCode 216. Combined Sum III (2022.08.04)
技术干货 | 基于 MindSpore 实现图像分割之豪斯多夫距离
Oracle 19.3 restart 环境
Opencv算术操作
Login function and logout function (St. Regis Takeaway)
DFINITY 基金会创始人谈熊市沉浮,DeFi 项目该何去何从
JS introduction to reverse the recycling business network of learning, simple encryption mobile phone number
电竞、便捷、高效、安全,盘点OriginOS功能的关键词
R语言ggplot2可视化:可视化密度图(Density plot)、可视化多个分组的密度图、数据点分布在箱图中间、添加主标题、副标题、题注信息
2022 Hangzhou Electric Power Multi-School Session 6 1008.Shinobu Loves Segment Tree Regular Questions
[Unity] [UGUI] [Display text on the screen]
如何选币与确定对应策略研究
uniapp connect ibeacon
告白数字化转型时代:麦聪软件以最简单的方式让企业把数据用起来
上位机开发C#语言:模拟STC串口助手接收单片机发送数据
SQL外连接之交集、并集、差集查询
PCB布局必知必会:教你正确地布设运算放大器的电路板
MySQL之数据视图
【综合类型第 35 篇】程序员的七夕浪漫时刻
Confessing in the era of digital transformation: Mai Cong Software allows enterprises to use data in the easiest way