CTime と struct tm の挿入子
struct tmとMFCのCTimeに対して挿入子を定義したのであげておく。コンソールにログを出力するときにでもまた使うかと思って。
// 定義
std::ostream& operator<< ( std::ostream& o, const CTime& rhs )
{
struct tm* t = rhs.GetLocalTm( NULL );
return o << t;
}
std::ostream& operator<< ( std::ostream& o, const struct tm* rhs )
{
CString s;
s.Format( "%04d/%02d/%02d %02d:%02d:%02d",
rhs->tm_year + 1900,
rhs->tm_mon + 1,
rhs->tm_mday,
rhs->tm_hour,
rhs->tm_min ,
rhs->tm_sec );
return o << (LPCTSTR)s;
}
// 宣言
extern std::ostream& operator<< ( std::ostream& o, const struct tm* rhs );
extern std::ostream& operator<< ( std::ostream& o, const CTime& rhs );
トラックバック
- このエントリーにトラックバック:
- http://frog.raindrop.jp/cgi-bin/mt/mt-tb.cgi/278
コメント