#include<iostream>
#include<cstring>
#include<fstream>
#include<sstream>
using namespace std
;
class Time
{
public:
Time(int year
, int mon
, int day
, int hour
, int min
, int sec
)
:_year(year
), _mon(mon
), _day(day
), _hour(hour
), _min(min
), _sec(sec
)
{
}
friend void outTime(ostream
&, const Time
&);
private:
int _year
;
int _mon
;
int _day
;
int _hour
;
int _min
;
int _sec
;
};
void outTime(ostream
&os
, const Time
&tm
)
{
os
<< dec
<< right
;
os
<< tm
._year
<< '.';
os
.width(2);
os
.fill('0');
os
<< tm
._mon
<< '.';
os
.width(2);
os
.fill('0');
os
<< tm
._day
<< '\t';
os
.width(2);
os
.fill('0');
os
<< tm
._hour
<< ':';
os
.width(2);
os
.fill('0');
os
<< tm
._min
<< ':';
os
.width(2);
os
.fill('0');
os
<< tm
._sec
<< endl
;
}
void main()
{
cout
.put('a');
char buf
[] = "blank ! \n";
cout
.write(buf
, strlen(buf
));
cout
.width(10);
cout
.fill('$');
cout
<< 222 << endl
;
cout
<< "b";
cout
.setf(ios
::hex
, ios
::basefield
);
cout
<< hex
<< left
<< 66 << endl
;
cout
<< boolalpha
<< true << endl
;
outTime(cout
, Time(2013, 10, 5, 6, 2, 10));
fstream fs
;
fs
.open("time.txt", ios
::out
);
outTime(fs
, Time(2013, 4, 5, 6, 7, 8));
fs
.close();
stringstream strs
;
outTime(strs
, Time(2013, 4, 5, 6, 7, 8));
string str
;
strs
>> str
;
cout
<< str
;
cout
<< "------------";
strs
>> str
;
cout
<< str
;
cout
<< endl
;
}
转载请注明原文地址: https://www.6miu.com/read-13346.html