phải nạp chồng toán tử << thế nào để khi xuất ngày tháng năm nhập vào( theo định dang DD/MM/yyyy thì nó xuất ra được đúng ạ
vd nhập 18/5/2018 thì lát xuất ra đúng như vậy đó
Nạp chồng toán tử << để in ra ngày theo định dạng DD/MM/yyyy
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
#pragma once
class Date
{
private:
int ngay, thang, nam;
public:
friend istream &operator >> (istream &input, Date &D)
{
input >>ngay>>thang>>nam;
return input;
}
/* 18/5/2018 */
friend ostream &operator << (ostream& output,const Date &D) {
output <<"the Date is: "<<
return output;
}
Date();
~Date();
};
class ngày tháng năm của e như vậy ạ
friend ostream &operator << (ostream& output,const Date &D) {
output <<"the Date is: "<< D.ngay << "/" << D.thang << "/" << D.nam;
return output;
}
Thế thôi là được phải không nhỉ?
1 Like
ko anh ơi
#include "Date.h"
int main() {
Date d1, d2;
cout << "nhap d1: ";
cin >> d1;
cout << "nhap d2: ";
cin >> d2;
cout << "d1: " << d1 << endl;
cout << "d2: " << d2 << endl;
system("pause");
return 0;
}
đây là body file main.c
nhập vào thì đc nhưng xuất thì nó ko ra đúng định dạng dd/MM/yyyy
cout << "d1: ";
cout << d1 << endl;
xem sao.
2 Likes
có lẽ phải dùng 1 cái gì đó để lấy dấu " / " khi mình nhập kiểu date
vd nhấp 15/2/2018



83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?