본문 바로가기

c++60

1. HelloWorld 코드 간략 분석 Main.cpp 코드 간략 분석 다른 프로그램들과 동일하게 진입점의 기능을 하는 코드. ▼ cocos2d 네임스페이스 사용한다는 의미. // main.cpp USING_NS_CC // CCPlatformMacros.h #define USING_NS_CC using namespace cocos2d ▼ 윈도우 운영체제에서 제공하는 윈도우 창 전용 Main 함수로 진입한다. int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { } ▼ 싱글턴(Singleton)으로 구현되어있다. AppDelegate app; return Application::getInstance()->run(); 싱.. 2021. 1. 28.
2. 간단한 탑뷰 게임 출구로 나가면 게임이 종료된다. 코인을 먹으면 카운트는 올라간다.. ▼ 실행화면 ▼ 전체코드 #include #include #include const static unsigned int FRAME = 30; const static unsigned int FPS = (1000 / FRAME); const static unsigned int WIDTH = 10; const static unsigned int HEIGHT = 10; const static unsigned int KEY_LEFT = 37; const static unsigned int KEY_TOP = 38; const static unsigned int KEY_RIGHT = 39; const static unsigned int KEY_DOW.. 2021. 1. 27.
20210127(수) std::sort() CPP 표준 라이브러리 에 정의되어 있는 함수. 기본적으로 오름차순이며 내림차순으로 지정할 수도 있다. ▼ 사용법 sort(v.begin(), v.end()); sort(v.begin(), v.end(), greater()); sort(v.begin(), v.end(), compare()); ▼ 예시 코드 #include #include #include void Print(int* arr) { printf("arr[] : "); for (int i = 0; i < 10; i++) printf("%d ", arr[i]); printf("\n"); } int main() { int arr[10] = { 3,4,2,4,5,1,2,3,5,0 }; Print(arr); std::sort(ar.. 2021. 1. 27.
6. STD::SORT STD::SORT ▼ 관련 개념 Loop & Template & STD ▼ 구현 코드 #include template bool Compare(T lhs, T rhs) { return (lhs < rhs); } int main() { std::array iArr = { 5, 4, 3, 2, 1 }; std::sort(iArr.begin(), iArr.end(), Compare); return (0); } CPP A.11에서 사용할 수 있는 std::sort를 사용한 방법이다. A.11를 지원하는 CPP 컴파일러라면 대부분의 경우 프로그래머가 직접 구현한 정렬 함수에 비해서 높은 성능을 낸다. (한가지 정렬법으로 구현된게 아니라 경우에 따라 최적의 방법으로 바꾸는 방식으로 되어있다.) 다른 알고리즘 문제를 .. 2021. 1. 27.