File Handling Basics

In Python

# Writing
with open("data.txt", "w") as f:
    f.write("Hello, File!")

# Reading
with open("data.txt", "r") as f:
    content = f.read()
    print(content)

In C++

#include <fstream>
#include <iostream>
using namespace std;

int main() {
    // Writing
    ofstream outFile("data.txt");
    outFile << "Hello, File!" << endl;
    outFile.close();

    // Reading
    ifstream inFile("data.txt");
    string content;
    while (getline(inFile, content)) {
        cout << content << endl;
    }
    inFile.close();

    return 0;
}