我自己创建了一个IO操作子如下:template <class charT, class traits>
inline
std::basic_ostream<charT, traits>&
outputtime (std::basic_ostream<charT, traits>& strm)
{
 SYSTEMTIME       now; GetLocalTime(&now);
 strm << setfill('0') << now.wYear << "/"
      << setw(2) << now.wMonth << "/"
      << setw(2) << now.wDay << " "
      << setw(2) << now.wHour << ":"
      << setw(2) << now.wMinute << ":"
      << setw(2) << now.wSecond << "."
      << setw(3) << now.wMilliseconds << std::setw(20) << std::setfill(' ');
 return strm;
}
在程序运行过程中没有任何异常。但是一旦当我的程序打算退出时,调用此操作子就会
出现一个错误。在vc的debug窗口中会显示
First chance exception:access 0xc000005.....
之后,我再打印任何内容都只是打印出错时输入的字符内容。当我发现可能是这里出现情况后,我将操作子改为如下的形式程序不会出错。
template <class charT, class traits>
inline
std::basic_ostream<charT, traits>&
outputtime (std::basic_ostream<charT, traits>& strm)
{
 SYSTEMTIME       now;
 char        timebuf[32];
 GetLocalTime(&now);
 sprintf(timebuf,
   "%d/%2d/%2d %2d:%2d:%2d.%3d",
   now.wYear,
   now.wMonth,
   now.wDay,
   now.wHour,
   now.wMinute,
   now.wSecond,
   now.wMilliseconds);
 strm << timebuf << std::setw(20) << std::setfill(' ');
 return strm;
}
我不知道我是否已经找到了问题所在(所谓的解决了问题,只不过是采用了一个替代方
案)?是不是我在使用IO Stream时需要注意其他的事项?还望各位高手给我指点迷
津。谢谢!