C++switch 语句

C++switch 语句

C++ Linux 下字符串简单显示颜色的示例,使用switch语句:

#include

#include

using namespace std;

void printcolor(string color, string str)

{

int clr;

string head;

string tail;

string display;

if(color=="red") clr=1;

if(color=="green") clr=2;

switch(clr){

case 1:{

head="\033[31m";

tail="\033[0m";

display=head+str+tail;

break;

}

case 2:{

head="\033[32m";

tail="\033[0m";

display=head+str+tail;

break;

}

default:{

display=str;

break;

}

}

cout << display << endl;

}

int main ()

{

printcolor("red", "helloworld!");

printcolor("green", "helloworld!");

return 0;

}

Jailman Jailman

xma***man.com

9年前 (2017-07-24)

相关手记

365bet取款要多久 查找设备位置共享功能介绍及常见问题
365彩票最新版app下载 台江史志 | 疍民:汉族的支系群体
365彩票最新版app下载 脸油是什么原因导致的

脸油是什么原因导致的

12-26 👁️ 2932
365彩票最新版app下载 手機連投影機完全攻略:設定教學與常見問題一次搞定
365彩票最新版app下载 萦字组词

萦字组词

01-14 👁️ 3219
365bet取款要多久 30到40万买什么车好

30到40万买什么车好

01-16 👁️ 7145