三元运算符

来源:互联网 发布:如何登陆我的淘宝店铺 编辑:程序博客网 时间:2024/04/30 11:53

三元运算符  “? : ”符号的运用


#include<iostream>#include<stdio.h>#include<string>using namespace std;int main(){char name[10];int sex;cout << "输入名称"<< endl;cin >> name;cout << "请输入1或者0,1代表男,0代表女" << endl;cin >> sex;cout << "-------------------------------\n" << endl;cout << "       姓名" << name << "        " << endl;char* strsex = (sex == 1) ? "男" : "女";cout << "      性别" << strsex << "    " << endl;cout << "--------------------------------" << endl;    system("pause");return 0;}


0 0
原创粉丝点击