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

//

 

#include "stdafx.h"

#include "01.h"

#include <afxtempl.h>

#include "afxcoll.h"

#include "afxtempl.h"

#include <time.h>

#include <iostream>

 

 

#ifdef _DEBUG

#define new DEBUG_NEW

#endif

 

 

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

 

CWinApp theApp;

 

using namespace std;

 

struct Point3D {

        int x, y, z;

        Point3D() {}

        Point3D(int x0, int y0, int z0) { x = x0; y = y0; z = z0; }

};

 

 

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

        {

 

               // TODO: 응용프로그램의동작은여기에서코딩합니다.

               /*

               CArray<Point3D, Point3D&> array;

               array.SetSize(5);

               for(int i=0; i<5; i++) {

               Point3D pt(i, i*10, i*100);

               array[i] = pt;

               }

               for(int i=0; i<5; i++) {

               Point3D pt = array[i];

               cout << pt.x << ", " << pt.y << ", " << pt.z << endl;

               }

 

 

               CUIntArray array;

               array.SetSize(5);

               for(int i=0; i<5; i++)        // 배열원소삽입

               array[i] = i;

              

               array.InsertAt(3, 77);        //중간에하나삽입

 

               for(int i=0; i<array.GetSize(); i++)  // 배열원소삭제

               cout << array[i] << endl;

               cout << endl;

              

               array.RemoveAt(3);

               for(int i=0; i<array.GetSize(); i++)

               cout << array[i] << endl;

               */

              

               // 1~10사이의랜덤수를100개를넣어주고그중에서입력받은수를지워주는프로그램

               /*/////////////////////////

               int i,n;

               CList <int,int&> list;

               srand(time(NULL));

               for(i=0; i< 100; i++) {

                       n = rand()%10+1;

                       list.AddTail(n);

               }

 

               int t;

               cout << "정수입력: ";

               cin >> t;

 

               POSITION pos;

 

               pos = list.Find(t);

               while(pos !=NULL) {

                       list.RemoveAt(pos);

                       pos = list.Find(t);

               }

              

               pos = list.GetHeadPosition();

 

               while(pos !=NULL) {

                       n = list.GetNext(pos);

                       cout << n << " ";

               }

               cout << endl;

               /////////////////////////////////*/

 

              

               // map의특징은구조자체가검색에특화되어key값으로인해한번에찾아간다.

               CMapStringToString map;               //키도스트링데이터도스트링

               map["사과"] = "Apple";        //한글이키     [] = 브레이크잇

               map["딸기"] = "Strawberry";

               map["포도"] = "Grape";

               map["우유"] = "Milk";

 

               CString str;

               if(map.Lookup("딸기", str))   //찾을때는반드시키로찾는다. //레퍼런스로데이터를가져온다. str

                       cout << "딸기-> " << (LPCTSTR)str << endl;

               POSITION pos = map.GetStartPosition();

               while(pos != NULL){

                       CString strKey, strValue;

                       map.GetNextAssoc(pos, strKey, strValue);

                       cout << (LPCTSTR)strKey << " -> " <<

                              (LPCTSTR)strValue << endl;

               }

               map.RemoveKey("우유");

               map["수박"] = "Watermelon";           // 없는걸이렇게하면자동입력이된다. 있는걸적으면수정이된다.

               pos = map.GetStartPosition();

               while(pos != NULL){

                       CString strKey, strValue;

                       map.GetNextAssoc(pos, strKey, strValue);

                       cout << (LPCTSTR)strKey << " -> " <<

                              (LPCTSTR)strValue << endl;

               }

               //"사과", CString("사과") 의차이점: ( char * // (LPCSTR)  ) , 이름없는CString 객체

        }

        return nRetCode;

}

 

 

+ Recent posts