C++/summary

2장 유틸리티 집합 클래스

gandus 2010. 11. 22. 10:52

// util  집합.cpp : 콘솔응용프로그램에대한진입점을정의합니다.

#include "stdafx.h"

#include "util  집합.h"

 

#ifdef _DEBUG

#define new DEBUG_NEW

#endif

 

 

// 유일한응용프로그램개체입니다.

 

CWinApp theApp;

 

using namespace std;

 

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])

{

        int nRetCode = 0;

 

        // MFC를초기화합니다. 초기화하지못한경우오류를인쇄합니다.

        if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))

        {

               // TODO: 오류코드를필요에따라수정합니다.

               _tprintf(_T("심각한오류: MFC를초기화하지못했습니다.\n"));

               nRetCode = 1;

        }

        else

        {

 

               /**   CString 연습

 

               CString str1;

               str1 = "안녕하세요.";

               CString str2("오늘은");

               CString str3(str2);

               CString str4 = str1 + " " + str2 + "즐거운날입니다.";

               cout<<str1 <<endl;

               cout<<str2 <<endl;

               cout<<str3 <<endl;

               cout<<str4 <<endl;

               str4 += " 하하하";

               cout<<(LPCTSTR)str4 <<endl;

 

 

               CString st;

               st.LoadString(Test);

               cout<< st<<endl;

 

               **/

 

       

               /* CRect , CPoint

 

               CRect rect1;

               rect1.SetRect(0,0,200,100);

               CRect rect2(0,0,200,100);

 

               if(rect1 == rect2)

                       cout<<"두직사각형의좌표가같습니다."<<endl;

 

               else

                       cout<<"두직사각형의좌표가다릅니다."<<endl;

 

               RECT rect = {100, 100, 300, 200};

               CRect rect3(rect);

               cout<< rect3.Width() << " " <<rect3.Height() <<endl;

 

               CPoint pt(200, 150);

              

               if(rect3.PtInRect(pt))

                       cout<<"사각형안에점이있습니다." <<endl;

               else

                       cout<<"사각형안에점이없습니다." <<endl;

 

               */

 

 

 

 

 

               // CTime 연습

 

               CTime theTime;

 

               char *date[7]  = {"","","","","","",""};

 

               theTime = CTime ::GetCurrentTime(); // 현재날짜를가져오는함수이다.

 

               CString str;

               str.Format("현재시간은%d%d%d초입니다.",

                       theTime.GetHour(), theTime.GetMinute(), theTime.GetSecond() );

 

               cout<< date[theTime.GetDayOfWeek()-1] <<endl;

               cout<< (LPCTSTR)str <<endl;  

 

 

 

               // 실습문제오늘부터1000일후의날짜는??

 

 

               /*

               CTimeSpan( ) throw( );

              

               CTimeSpan(

                       __time64_t time

               ) throw( );

              

               CTimeSpan(

                       LONG lDays,

                       int nHours,

                       int nMins,

                   int nSecs

               ) throw( );

 

               */

 

 

               // 초기화를담당한다.

               CTimeSpan timeSpan(1000, 0, 0, 0);

 

              

               //  타임스팬=  타임- 타임

               //  타임    =  타임스팬+ 타임

               theTime += timeSpan;

 

 

               cout<< theTime.GetYear() <<endl;

              

              

 

        }

 

 

        return nRetCode;

}