运行以下代码:
1 #include <iostream>
2 int main(int argc, char** argv)
3 {
4 time_t t1 = time(0);
5 time_t t(0);
6 std::cout<<"BUG LINE"<<std::endl<< ctime(&t) << ctime(&t1) ;
7 std::cout<<"PRINTS FINE HERE"<<std::endl;
8 std::cout<< ctime(&t);
9 std::cout<< ctime(&t1);
10 return 0;
11 }
构建:g++ test1.cpp
Output:
./a.out
BUG LINE
Thu Jan 1 01:00:00 1970
Thu Jan 1 01:00:00 1970
PRINTS FINE HERE
Thu Jan 1 01:00:00 1970
Wed Jul 10 16:31:48 2013
为什么代码#6 中的流变得奇怪?