当前位置:网站首页>解决【命令行/终端】颜色输出问题
解决【命令行/终端】颜色输出问题
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")
... # 你的其他代码
边栏推荐
- The founder of the DFINITY Foundation talks about the ups and downs of the bear market, and where should DeFi projects go?
- Opencv图像缩放和平移
- 【MindSpore易点通机器人-01】你也许见过很多知识问答机器人,但这个有点不一样
- 牛刀小试基本语法,Go lang1.18入门精炼教程,由白丁入鸿儒,go lang基本语法和变量的使用EP02
- Chapter 4: In the activiti process, variable transmission and acquisition process variables, setting and acquiring multiple process variables, setting and acquiring local process variables "recommende
- Score interview (1)----related to business
- MySQL之数据视图
- What is SPL?
- 2022华数杯数学建模思路分析交流
- Data Middle Office Construction (10): Data Security Management
猜你喜欢

Complete image segmentation efficiently based on MindSpore and realize Dice!

STM32+ULN2003 drives 28BYJ4 stepper motor (forward and reverse according to the number of turns)

NowCoderTOP35-40 - continuous update ing

Create a Dapp, why choose Polkadot?

012_SSS_ Improving Diffusion Model Efficiency Through Patching

012年通过修补_sss_提高扩散模型效率

SQL Outer Join Intersection, Union, Difference Query

高质量 DeFi 应用构建指南,助力开发者玩转 DeFi Summer

DFINITY 基金会创始人谈熊市沉浮,DeFi 项目该何去何从

Leetcode刷题——623. 在二叉树中增加一行
随机推荐
[Android] How to use RecycleView in Kotlin project
我们的Web3创业项目,黄了
Meteorological data processing example - matlab string cutting matching and R language date matching (data splicing)
Introduction to SD NAND Flash!
开发常用手册链接分享
阿里全新推出:微服务突击手册,把所有操作都写出来了PDF
MySQL事务
LeetCode 216. Combined Sum III (2022.08.04)
数据可视化(一)
化繁为简!阿里新产亿级流量系统设计核心原理高级笔记(终极版)
[强网杯2022]WP-UM
JS逆向入门学习之回收商网,手机号码简易加密解析
阿里顶级架构师多年总结的JVM宝典,哪里不会查哪里!
How does the official account operate and maintain?Public account operation and maintenance professional team
第八章:activiti多用户任务分配
The founder of the DFINITY Foundation talks about the ups and downs of the bear market, and where should DeFi projects go?
单片机:温度控制DS18B20
这份阿里强推的并发编程知识点笔记,将是你拿大厂offer的突破口
Login function and logout function (St. Regis Takeaway)
数据可视化(二)