Bruce Eckel's Thinking in C++, 2nd Ed | Contents | Prev | Next |
//: C18:Stype.cpp // Type a file to standard output #include <fstream> #include <iostream> #include "../require.h" using namespace std; int main(int argc, char* argv[]) { requireArgs(argc, 1); // Must have a command line ifstream in(argv[1]); assure(in, argv[1]); // Ensure file exists cout << in.rdbuf(); // Outputs entire file } ///:~
//: C18:Sbufget.cpp // Get directly into a streambuf #include <fstream> #include <iostream> #include "../require.h" using namespace std; int main() { ifstream in("Sbufget.cpp"); assure(in, "Sbufget.cpp"); while(in.get(*cout.rdbuf())) in.ignore(); } ///:~