File I/O

This example demonstrates how to read from and write to files.

cppCopy code#include <iostream>
#include <fstream>

int main() {
    std::ofstream outFile("example.txt");
    outFile << "Hello, file!" << std::endl;
    outFile.close();

    std::ifstream inFile("example.txt");
    std::string line;
    while (std::getline(inFile, line)) {
        std::cout << line << std::endl; // Output: Hello, file!
    }
    inFile.close();
    return 0;
}

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *