您的位置:首页 > 其它

三元运算符

2015-09-16 20:01 225 查看
三元运算符 “? : ”符号的运用

#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: