C http www ilit co kr cx 8537naver

  • Slides: 18
Download presentation
[이것이 C++ 이다] http: //www. ilit. co. kr cx 8537@naver. com 최호성

[이것이 C++ 이다] http: //www. ilit. co. kr cx 8537@naver. com 최호성

Chapter 1 C와는 다른 C++

Chapter 1 C와는 다른 C++

Hello. World로 본 C++ Hello. Cpp. cpp 직관적으로 << 연산자가 가리키는 방향이 모두 std:

Hello. World로 본 C++ Hello. Cpp. cpp 직관적으로 << 연산자가 가리키는 방향이 모두 std: : cout으로 향하고 있다. // Hello. Cpp. cpp : 콘솔 응용 프로그램에 대한 진입점을 정의합니다. // #include "stdafx. h" #include <iostream> int _tmain(int argc, _TCHAR* argv[]) { std: : cout << "Hello, World" << std: : endl; return 0; }

std: : out Cout. Sample. cpp 자료형을 cout 객체가 알맞은 자료형을 선택해 출력한다. #include

std: : out Cout. Sample. cpp 자료형을 cout 객체가 알맞은 자료형을 선택해 출력한다. #include "stdafx. h" #include <iostream> int _tmain(int argc, { std: : cout << std: : cout << return 0; } _TCHAR* argv[]) 10 << std: : endl; 10 U << std: : endl; 10. 5 F << std: : endl; 10. 5 << std: : endl; 3 + 4 << std: : endl;

std: : cin >> instance #include "stdafx. h" #include <string> #include <cstdio> #include <iostream>

std: : cin >> instance #include "stdafx. h" #include <string> #include <cstdio> #include <iostream> int _tmain(int argc, _TCHAR* argv[]) { int n. Age; std: : cout << "나이를 입력하세요. " << std: : endl; std: : cin >> n. Age; char sz. Job[32]; std: : cout << "직업을 입력하세요. " << std: : endl; std: : cin >> sz. Job; std: : string str. Name; std: : cout << "이름을 입력하세요. " << std: : endl; std: : cin >> str. Name; std: : cout << "당신의 이름은 " << str. Name << "이고, " << "나이는 " << n. Age << "살이며, " << "직업은 " << sz. Job << "입니다. " << std: : endl; return 0; }

new와 delete 연산자 New. Delete. Sample. cpp #include "stdafx. h" #include <iostream> int _tmain(int

new와 delete 연산자 New. Delete. Sample. cpp #include "stdafx. h" #include <iostream> int _tmain(int argc, _TCHAR* argv[]) { // 인스턴스만 동적으로 생성하는 경우 int *p. Data = new int; // 초깃값을 기술하는 경우 int *p. New. Data = new int(10); *p. Data = 5; std: : cout << *p. Data << std: : endl; std: : cout << *p. New. Data << std: : endl; delete p. Data; delete p. New. Data; }

new와 delete 연산자 배열로 생성한 것은 반드시 배열로 삭제한다. #include "stdafx. h" #include <iostream>

new와 delete 연산자 배열로 생성한 것은 반드시 배열로 삭제한다. #include "stdafx. h" #include <iostream> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { // 객체를 배열 형태로 동적 생성한다. int *arr = new int[5]; for (int i = 0; i < 5; ++i) arr[i] = (i + 1) * 10; for (int i = 0; i < 5; ++i) cout << arr[i] << endl; // 배열 형태로 생성한 대상은 반드시 배열 형태를 통해 삭제한다! delete[] arr; return 0; }