Ray's playground

 

Iostreams part1(Chapter 2 of Thinking in C++ Vol 2)

code
 1 #include <iostream>
 2 #include <fstream>
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     ifstream in("IOfile.cpp");
 8     ofstream out("IOfile.out");
 9     out << in.rdbuf();
10     in.close();
11     out.close();
12 
13     ifstream in2("IOfile.out", ios::in | ios::out);
14     ostream out2(in2.rdbuf());
15     cout << in2.rdbuf();
16     out2 << "Where does this end up?";
17     out2.seekp(0, ios::beg);
18     out2 << "And what about this?";
19     in2.seekg(0, ios::beg);
20     cout << in2.rdbuf();
21 }

 

posted on 2010-12-12 15:54  Ray Z  阅读(170)  评论(0编辑  收藏  举报

导航