您的位置:首页 > 编程语言 > C语言/C++

常用的c_c++代码

2012-02-27 08:03 162 查看
#include <iostream>

#include <time.h>

int main()

{

time_t curtime=time(0);

tm tim =*localtime(&curtime);

int day,mon,year;

day=tim.tm_mday;

mon=tim.tm_mon;

year=tim.tm_year;

std::cout<<year+1900<<"年"<<mon+1<<"月"<<day<<"日"<<std::endl;

system("pause");

return 0 ;

}

////对传入的不定长的参数进行处理,一般用于打印日志中

writelog(char *format,...)

{

va_list args;

char buf[4096];

memset(buf,0,4096);

va_start(args, format);

vsprintf_s(&buf[strlen(buf)], 4096, format, args);

va_end(args);

string strResult(buf);

..... /////以下进行其它的处理

}

//////A,B类互相引用的方式

////A.h 文件中:

class B; /////注意A.h 不可以包含B.h

....

void fun(B *pB) ;

/////end of A.h

/////A.cpp 文件中:

#include "B.h"

void fun(B *pB)

{ ....};

... /////end of A.cpp

//////B.h 文件中

#include "A.h"

A *m_pA;

.....

/////end of B.h

//////B.cpp 文件中

#include "B.h"

....

m_pA = xxxx;

///////end of B.cpp
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: