#include <unistd.h>
#include <iostream>
#include<ctime>
#include<sstream>
using namespace std;
int main(int argc , char* argv[])
{
struct tm *times;
time_t t;
t=time(0);
times=localtime(&t);
char chTime[32];
strftime(chTime,32,"%Y/%m/%d",times);
cout<<times->tm_year+1900<<endl;
cout<<chTime<<endl;
stringstream ss;
ss<<chTime;
cout<<ss.str()<<endl;
return 0;
}
在C++中stringstream 相当于C中的sprintf()函数,stringstream 定义在sstream中
输出结果为:
2011
2011/03/14
2011/03/14