Modernes C++ programmieren

Okt 20, 2024

lst-0028-book.cpp

// https://godbolt.org/z/hPaz3a3sE
#include <fstream>
#include <iostream>
using std::cout;
int main() {
    std::ifstream file("44fstream07.cpp");
    if( !file ) { /* Error */ cout << "ERR\n"; return 1; }
    std::ofstream filecopy("backup.cpp");
    if( !filecopy ) { /* Error */ cout << "ERR\n"; return 1; }
    std::string buffer;
    while( getline(file, buffer) ) {
        filecopy << buffer << std::endl;
        cout << buffer << std::endl;
    }
    if( file.eof() ) {
        file.clear();
    }
}