Iostreams part1(Chapter 2 of Thinking in C++ Vol 2)
2010-12-12 15:54
429 查看
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();
in.close();
out.close();
ifstream in2("IOfile.out", ios::in | ios::out);
ostream out2(in2.rdbuf());
cout << in2.rdbuf();
out2 << "Where does this end up?";
out2.seekp(0, ios::beg);
out2 << "And what about this?";
in2.seekg(0, ios::beg);
cout << in2.rdbuf();
}
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();
in.close();
out.close();
ifstream in2("IOfile.out", ios::in | ios::out);
ostream out2(in2.rdbuf());
cout << in2.rdbuf();
out2 << "Where does this end up?";
out2.seekp(0, ios::beg);
out2 << "And what about this?";
in2.seekg(0, ios::beg);
cout << in2.rdbuf();
}
相关文章推荐
- Iostreams part2(Chapter 2 of Thinking in C++ Vol 2)
- Templates in depth(Chapter 3 of Thinking in C++ Vol 2)
- STL Containers & Iterators part1(Chapter 4 of Thinking in C++ Vol 2)
- STL Containers & Iterators part2(Chapter 4 of Thinking in C++ Vol 2)
- The C in C++(Chapter 3 of Thinking in C++)
- [THINKING IN C++]CHAPTER 03:EXERCISE 01
- Name Control(Chapter 10 of Thinking in C++)
- Operator Overloading part 1(Chapter 12 of Thinking in C++)
- Operator Overloading part 2(Chapter 12 of Thinking in C++)
- Summarizes chapter one of datastructures and program design in C++
- [THINKING IN C++]CHAPTER 03:EXERCISE 03
- Initialization & Cleanup(Chapter 6 of Thinking in C++)
- Operator Overloading part 3(Chapter 12 of Thinking in C++)
- [THINKING IN C++]CHAPTER 04:EXERCISE 04
- Data Abstraction(Chapter 4 of Thinking in C++)
- Constants(Chapter 8 of Thinking in C++)
- [THINKING IN C++]CHAPTER 03:EXERCISE 06
- [THINKING IN C++]CHAPTER 03:EXERCISE 07
- [THINKING IN C++]CHAPTER 03:EX 25
- Function Overloading & Default Arguments(Chapter 7 of Thinking in C++)