当前位置:网站首页>解决【命令行/终端】颜色输出问题
解决【命令行/终端】颜色输出问题
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")
... # 你的其他代码
边栏推荐
- SQL外连接之交集、并集、差集查询
- [Translation] Chaos Net + SkyWalking: Better observability for chaos engineering
- three.js debugging tool dat.gui use
- 创建一个 Dapp,为什么要选择波卡?
- FPGA:基础入门按键控制LED灯
- 用户考试分数大于单科科目平均分的查询
- Voice-based social software development - making the most of its value
- FPGA: Basic Getting Started Button Controlling LED Lights
- 【Office】Microsoft Office下载地址合集(微软官方原版离线安装下载)
- 一文道清什么是SPL
猜你喜欢
字节一面:TCP 和 UDP 可以使用同一个端口吗?
【温度预警程序de开发】事件驱动模型实例运用
2022 Huashu Cup Mathematical Modeling Question A Optimization Design Ideas for Ring Oscillators Code Sharing
DFINITY 基金会创始人谈熊市沉浮,DeFi 项目该何去何从
Create a Dapp, why choose Polkadot?
MySQL transactions
The founder of the DFINITY Foundation talks about the ups and downs of the bear market, and where should DeFi projects go?
数据可视化(一)
Meteorological data processing example - matlab string cutting matching and R language date matching (data splicing)
[强网杯2022]WP-UM
随机推荐
High-quality DeFi application building guide to help developers enjoy DeFi Summer
七夕来袭!还要做CDH数据迁移怎么办?来看看DistCp
首次去中心化抢劫?近2亿美元损失:跨链桥Nomad 被攻击事件分析
用KUSTO查询语句(KQL)在Azure Data Explorer Database上查询LOG实战
SQL外连接之交集、并集、差集查询
第四章:redis 数组结构的set和一些通用命令「建议收藏」
JS introduction to reverse the recycling business network of learning, simple encryption mobile phone number
【 temperature warning program DE development 】 event driven model instance
Dynamics 365Online PDF导出及打印
The century-old Nordic luxury home appliance brand ASKO smart wine cabinet in the three-temperature area presents the Chinese Valentine’s Day, and tastes the love of the delicacy
Oracle 19.3 restart 环境
上位机开发C#语言:模拟STC串口助手接收单片机发送数据
阿里全新推出:微服务突击手册,把所有操作都写出来了PDF
Getting started with Polkadot parachain development, this article is enough
PCB布局必知必会:教你正确地布设运算放大器的电路板
PCB layout must know: teach you to correctly lay out the circuit board of the op amp
多线程(进阶) - 2.5w字总结
第五章:activiti流程分流判断,判断走不同的任务节点
攻防世界-PWN-new_easypwn
深入理解 Istio 流量管理的超时时间设置