#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
// 1. copy 알고리즘에 대해서
void main()
{
int x[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
        int y[10];
        copy( x, x+10, y );
        for( int i = 0; i < 10; ++i )
        {
               cout << y[i] << endl;
        }
}
// 2. 출력반복자
void main()
{
        ostream_iterator<int> p( cout, " " );
        *p = 10;       // 10을 출력한후 자동으로 ++을 수행한다.
//      ++p;           // 실제로는 아무일도 하지 않는다.
        *p = 20;
int x[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
        // 배열을 화면에 출력하는 방법.
        copy( x, x+10, p );
}
// 3. 출력반복자 와 파일
void main()
{
        ofstream f("a.txt");   // 출력전용 파일생성.
        // 리스코프의 치환법칙- 부모가 들어 갈 수 있다면 자식도 들어갈 수 있다.???
        ostream_iterator<int> p( f, " " ); // 화일스트림을 가르키는 출력반복자
int x[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
        copy( x, x+10, p );    //!!!
}
// 4. 입력스트림 반복자
#include <fstream>
void main()
{
        ifstream f1("a.cpp"); // 현재 소스파일의 이름을 넣으세요.
        //istream_iterator<char> p1(f1), p2;  // 디폴트생성자는 EOF를 가르킨다.
        istreambuf_iterator<char> p1(f1), p2;
        ostream_iterator<char> p3(cout, "");
        copy( p1, p2, p3 );
}
