컴퓨터 과학 & 영상처리 관련/C / C++ 시간 계산 예제 꺄뜨르 2013. 11. 7. 12:16 //#pragma once #pragma comment(lib,"shell32.lib") //바탕화면 경로 #include <shlobj.h> //바탕화면 경로 #include <time.h> //시간 계산 #include <sys/timeb.h> // _ftime 밀리초 #include <stdio.h> #include <stdlib.h> #include <windows.h> #define timeCalc(func, timebuf, filepath, text) \ { \ writeCurrentTime(timebuf, filepath, "before ", text); \ func \ writeCurrentTime(timebuf, filepath, "after ", text); \ } struct _timeb timebuf; void writeCurrentTime(_timeb timeBuf, char* filepath, char* beforeAfter, char* text) { struct tm* time_now; //타임 구조체 FILE* fp; _ftime(&timeBuf); //밀리초 계산 time_now = localtime(&timeBuf.time); //밀리초를 현재시간으로 타임 구조체에 전달 fp = fopen(filepath, "a+"); if(strcmp(text, "")==0) //text가 비어있으면 그냥 초계산 안하고 개행 { fprintf(fp, "\n"); } else //그렇지 않으면 초 계산 { fprintf(fp, "%s : %s %02d:%02d:%02d:%d\n",beforeAfter, text, time_now->tm_hour, time_now->tm_min, time_now->tm_sec, timeBuf.millitm); } fclose(fp); } int main(void) { for(int i = 0 ; i < 60; i++) timeCalc(Sleep(1000);, timebuf, "timeCalc.txt", "sleep(1000)"); return 0; getchar(); getchar(); return 0; } //이렇게 한번 해볼까