C++ 输出颜色字体
#include <iostream>
#include <string>
using namespace std;
int main(){
cout << "这是原始颜色" << endl;
cout << "\033[30;1m这是黑色\033[0m" << endl;
cout << "\033[31;1m这是红色\033[0m" << endl;
cout << "\033[32;1m这是绿色\033[0m" << endl;
cout << "\033[33;1m这是黄色\033[0m" << endl;
cout << "\033[34;1m这是蓝色\033[0m" << endl;
cout << "\033[35;1m这是紫色\033[0m" << endl;
cout << "\033[36;1m这是青色\033[0m" << endl;
cout << "\033[37;1m这是白色\033[0m" << endl;
return 0;
}
结果如下:
如果颜色输出次数太多嫌麻烦,可以自己封装成一个函数,例如:
#include <iostream>
#include <string>
using namespace std;
void red_print(string out){
cout << "\033[31;1m"+out+"\033[0m" << endl;
}
int main(){
red_print("红色输出...");
return 0;
}
|