1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
#include <iostream>
#include <sstream>
#include <string>
using std::cout;
using std::cin;
using std::endl;
using std::ostream;
using std::istream;
using std::string;
using std::istringstream;
struct Date
{
int d;
int m;
int y;
Date(int dd=0,int mm=0, int yy=0)
:d(dd),m(mm),y(yy)
{}
};
bool from_string(Date & D)
{
string Str;
cin >> Str;
int first = Str.find("/");
int second = Str.find("/",first+1);
istringstream jour(Str.substr(0,first));
istringstream mois(Str.substr(first+1,second-first-1));
istringstream an(Str.substr(second+1));
return (jour >> D.d)&&(mois >> D.m)&&(an >> D.y);
}
ostream& operator << (ostream& flux, Date & D)
{
flux << D.d << "/" << D.m << "/" << D.y;
return flux;
}
istream& operator >> (istream& flux, Date & D)
{
flux >> D.d >> D.m >> D.y;
return flux;
}
int main ()
{
Date D1;
Date D2;
string s;
cout << "Entrez une date : ";
from_string(D1);
cout << D1 << endl;
cout << "Entrez une autre date : ";
cin >> D2;
cout << "Vous avez entrez ces dates : " << D1 << " et " << D2 << endl;
cout << "Moi je vous propose plutot ces dates : " << Date(01,01,1970) << " et " << Date(03,03,2005) << endl;
return EXIT_SUCCESS;
} |
Partager