How To Output Colored Text To A Linux Terminal? - Tutorialspoint
- Home
- Whiteboard
- Online Compilers
- Practice
- Articles
- AI Assistant
- Jobs
- Tools
- Corporate Training
- Courses
- Certifications
- Switch theme
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Here we will see how to print some lines into the linux terminal with some color. Here we are doing anything special into C++ code. We are just using some linux terminal commands to do this. The command for this kind of output is like below.
\033[1;31m Sample Text \033[0mThere are some codes for text styles and colors. These are listed below.
| Color | Foreground Code | Background Code |
|---|---|---|
| Black | 30 | 40 |
| Red | 31 | 41 |
| Green | 32 | 42 |
| Yellow | 33 | 43 |
| Blue | 34 | 44 |
| Magenta | 35 | 45 |
| Cyan | 36 | 46 |
| White | 37 | 47 |
Some additional options are like below −
| Option | Code | Description |
|---|---|---|
| Reset | 0 | Back to normal (remove all styles) |
| Bold | 1 | Bold the text |
| Underline | 4 | Underline text |
| Inverse | 7 | Interchange colors of background and foreground |
| Bold off | 21 | Normal from bold |
| Underline off | 24 | Normal from Underline |
| Inverse off | 27 | Reverse of the Inverse |
Example
#include<iostream> using namespace std; main() { cout << "\033[1;31mThis is bold red text\033[0m\n"; cout << "\033[;32mGreen Text\033[0m\n"; cout << "\033[4;33mYellow underlined text\033[0m\n"; cout << "\033[;34mBlue text\033[0m\n"; }Output

karthikeya Boyini Updated on: 2019-07-30T22:30:26+05:30 9K+ Views
Kickstart Your Career
Get certified by completing the course
Get StartedTừ khóa » C++ 033 0m
-
Linux Console Color (the "\033[" Way) - Forum - C++
-
How Do I Output Coloured Text To A Linux Terminal? - Stack Overflow
-
C++ Cout Color Code Example
-
C++ Terminal Output Colors - Gists · GitHub
-
Git Shell Coloring - Gists · GitHub
-
How To Change Text Color In A Linux Terminal - CodeProject
-
6.2. Cursor Movement
-
C++ – How To Output Coloured Text To A Linux Terminal - ITecNote
-
How Do I Make Colored Text In C++? - Replit
-
ANSI Escape Code - Wikipedia
-
C++ Changes The Color Of Characters Output By The Terminal (Linux ...
-
Build Your Own Command Line With ANSI Escape Codes
-
Print Colorful Ascii Art In Cpp Console - ADocLib