Introduction To Object-Oriented Programming COMP2011: File I/O
Introduction To Object-Oriented Programming COMP2011: File I/O
Introduction To Object-Oriented Programming COMP2011: File I/O
Object-Oriented Programming
C++ Stream
A stream is simply a sequence of characters.
cout << "Enter the input filename: "; cin >> ip_file;
ifstream ifs(ip_file); // One way to create a fstream object
if (!ifs)
{ cerr << "Error: Can't open \"" << ip_file << "\"\n"; return -1; }
cout << "Enter the output filename: "; cin >> op_file;
ofstream ofs; ofs.open(op_file); // Another way to create a fstream object
if (!ofs)
{ cerr << "Error: Can't open \"" << op_file << "\"\n"; return -1; }
if (!ifs)
{ cerr << "Error: Can't open \"" << ip_file << "\"\n"; return -1; }