Group B

Q4: Write a C++ program that creates an output file, writes information to it, closes the file, opens it again as an input file, and reads the information from the file.

File Handling

Solution and implementation for Q4 from Object-Oriented Programming (oop).

grpB_4.c++ Download
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main() {
    const char* filename = "try.txt";

    // Create and write to the file
    ofstream outFile(filename);
    outFile << "Trying out new ways to create a file.";
    outFile.close();

    // Read and display the content of the file
    ifstream inFile(filename);
    cout << "Content of the File:\n";
    cout << inFile.rdbuf();
    inFile.close();

    return 0;
}

Other Questions in Object-Oriented Programming

See All Available Questions
Download