Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#include <iostream>
#include <cstdio>
using namespace std;
//コンストラクタのオーバーロードの例
class date {
int day, month, year;
public:
date(char *str);
date(int m, int d, int y) {
day = d;
month = m;
year = y;
}
void show() {
cout << month << '/' << day << '/' << year << endl;
}
};
date::date(char *str)
{
sscanf_s(str, "%d%*c%d%*c%d", &month, &day, &year);
}
int main()
{
date strDate("8/3/17");
date intDate(8, 3, 17);
strDate.show();
intDate.show();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment