sakukusa 2016-01-01 08:33 采纳率: 0%
浏览 1192

为何char【17】无法输入字符

#include
#include
using namespace std;
class Date{
public:
Date(int y, int m, int d);
~Date(){}
Date(){}
int getyear()const{ return year; }
int getmonth()const{ return month; }
int getday()const{ return day; }
Date(Date &birthday);
void enteringbirthday();
void showbirthday();
private:
int year;
int month;
int day;
};
Date::Date(int y, int m, int d){
year = y;
month = m;
day = d;
}
Date::Date(Date &birthday){
year = birthday.year;
month = birthday.month;
day = birthday.day;
}
void Date::enteringbirthday(){
cout << "年:";
cin >> year;
cout << "月:";
cin >> month;
cout << "日:";
cin >> day;
}
void Date::showbirthday(){
cout << "出身日期:" << year << "年" << month << "月" << day << "日" << endl;
}
class People{
public:
People(){}
People(string n, string s, char id[17]) :birthday(){
number = n;
sex = s;
strcpy_s(ID, id);
}
void entering();
void show();
~People(){}
private:
string number;
string sex;
char ID[17];
Date birthday;
};
void People::entering(){
cout << "录入编号:";
cin >> number;
cout << "录入性别(female,male):";
cin >> sex;
cout << "录入身份证:";
cin >> ID[17];
ID[17] = '\0';
cout << "录入出生日期:";
birthday.enteringbirthday();
}
void People::show(){
cout << "编号:" << number;
cout << "性别:" << sex;
cout << "身份证:" << ID;
birthday.showbirthday();
}
int main(){
People x;
x.entering();
x.show();
return 0;
}

  • 写回答

3条回答 默认 最新

  • devmiao 2016-01-01 08:33
    关注

    身份证18位加上\0需要19才够。

    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘