include iostream ios include ios ostream include ostream

  • Slides: 29
Download presentation

#include <iostream>와 전처리기. . <ios>헤더파일 . . . #include <ios>. . . <ostream>헤더파일 .

#include <iostream>와 전처리기. . <ios>헤더파일 . . . #include <ios>. . . <ostream>헤더파일 . . . #include <ostream>. . . #include <istream>. . <ios> <ostream> <istream>헤더파일 <istream> <iostream>헤더파일. . . #include <iostream> using namespace std; int main() { cout << "Hellon"; cout << "첫 번째 맛보기입니다. "; return 0; } Simple. C++. cpp <iostream> using namespace std; 전처리기 (preprocessor ) int main() { cout << "Hellon"; cout << "첫 번째 맛보기입니다. "; return 0; } 확장된 Simple. C++. cpp 컴파일 4

<iostream> 헤더 파일은 어디에? • <iostream> 파일은 텍스트 파일 • 컴파일러가 설치된 폴더 아래

<iostream> 헤더 파일은 어디에? • <iostream> 파일은 텍스트 파일 • 컴파일러가 설치된 폴더 아래 include 폴더에 존재 ü C: Program FilesMicrosoft Visual Studio 10. 0VCinclude 5

namespace 정의 • namespace : 식별자들에 대한 그룹 ü 예 : Microsoft, Samsung 네임스페이스

namespace 정의 • namespace : 식별자들에 대한 그룹 ü 예 : Microsoft, Samsung 네임스페이스 작성 namespace Microsoft { int g_MVar; int Plus(int x, int y); int Minus(int x, int y) } namespace Samsung { int g_Svar; int Plus(int x, int y); int Minus(int x, int y); } Microsoft 네임스페이스 Samsung 네임스페이스 11

namespace 사용 1) 네임스페이스를 지정해서 이름 사용 int main() { Samsung: : plus(x, y);

namespace 사용 1) 네임스페이스를 지정해서 이름 사용 int main() { Samsung: : plus(x, y); Samsung: : minus(x, y); Microsoft: : plus(x, y); } 2) using 키워드 사용 using namespace samsung : : 멤버연산자 int main() { plus(x, y); // Samsung: : plus(x, y) minus(x, y) // Samsung: : minus(x, y) Microsoft: : plus(x, y); } « std C++ 표준라이브러리와 관련된 코드를 정의한 name space <iostream> 헤더 파일에 선언된 모든 이름: std 이름 공간 안에 있음 #include<iostream> using namespace std; int main() { std: : cout << “Hellon”; } int main() { cout << “Hellon”; } 12

namespace 사용 1) 네임스페이스를 지정해서 이름 사용 #include <iostream> double area(int r); // 함수의

namespace 사용 1) 네임스페이스를 지정해서 이름 사용 #include <iostream> double area(int r); // 함수의 원형 선언 double area(int r) { // 함수 구현 return 3. 14*r*r; // 반지름 r의 원면적 리턴 } int main() { int n=3; char c='#'; std: : cout << c << 5. 5 << '-' << n << "hello" << true << std: : endl; std: : cout << "n + 5 = " << n + 5 << 'n'; std: : cout << "면적은 " << area(n); // 함수 area()의 리턴 값 출력 } 2) using 키워드 사용 #include <iostream> using namespace std; double area(int r); // 함수의 원형 선언 double area(int r) { // 함수 구현 return 3. 14*r*r; // 반지름 r의 원면적 리턴 } int main() { int n=3; char c='#'; cout << c << 5. 5 << '-' << n << "hello" << true << endl; cout << "n + 5 = " << n + 5 << 'n'; cout << "면적은 " << area(n); // 함수 area()의 리턴 값 출력 } 13