컴퓨터 썸네일형 리스트형 ofstream 클래스명 클래스 이름은 ofstream이다. 아무래도 Out File Stream의 약자일 것 같다. 기능 ofstream 클래스는 파일 쓰기 기능을 한다. 헤더 ofstream 클래스는 fstream 헤더를 포함해야 사용할 수 있다. 그리고 fstream 헤더 내부의 std 네임스페이스 안에 있는 것 같다. using std::ofstream 선언을 해줘야 사용할 수 있기 때문이다. 사용 예제 1 #include //endl 을 위한 헤더 #include //ofstream 을 위한 헤더 using std::endl; using std::ofstream; int main(void) { ofstream test("output.txt"); //파일 개방 for (int i = 0; i < 10; i++) .. 4-6. friend 선언 전역 함수에 대한 friend 선언 private로 선언된 멤버 변수는 외부 접근이 허용되지 않는다. 그러나 friend 선언을 통해서 private으로 선언된 멤버 변수의 접근을 허용할 수 있다. #include using std::cout; using std::endl; class Counter { int val; public: Counter() { val = 0; } void Printf() const { cout 4-4 클래스와 배열 객체 배열과 생성자 객체 배열은 말 그대로 객체를 배열의 형태로 선언한 것이다. #include using std::cout; using std::endl; class Point { int x; int y; public: Point() { cout 4-2. 캡슐화(Encapsulation) 캡슐화의 기본 개념 캡슐화란? 관련 있는 데이터오 함수를 하나의 단위로 묶는 것이다. 다시 이야기하면, 관련 있는 데이터와 함수를 클래스라는 하나의 캡슐 내에 모두 정의하는 것이다. 캡슐화가 잘 되지 않은 예 #include using std::cout; using std::endl; using std::cin; class Point { int x; //x 좌표의 범위: 0~100 int y; //y 좌표의 범위: 0~100 public: int GetX() { return x; } int GetY() { return y; } void SetX(int _x); void SetY(int _y); }; void Point::SetX(int _x) { if (_x 100) { //경계 검사 .. 4-1. 정보 은닉(Information Hiding) 정보 은닉(Information Hiding)의 필요성 #include using std::cout; using std::endl; using std::cin; class Point { public: int x; //x 좌표의 범위: 0~100 int y; //y 좌표의 범위: 0~100 }; int main(void) { int x, y; cout > x >> y; Point p; p.x = x; //문제의 원인, 멤버 변수의 외부 접근을 허용 p.y = y; //문제의 원인 cout 이전 1 ··· 73 74 75 76 77 78 79 ··· 88 다음