copy.cc
author Markus Bröker <mbroeker@largo.dyndns.tv>
Thu, 16 Apr 2009 12:49:12 +0200
changeset 50 a38f102556e5
parent 29 7abf6146898e
child 63 5a82f89d607e
permissions -rw-r--r--
khello: a nice kernel module committer: Markus Bröker <mbroeker@largo.homelinux.org>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     1
/**
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     2
 * Kopierprogramm für Dateien in C++
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     3
 * Copyright (C) 2008 Markus Bröker
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     4
 */
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     5
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     6
#include <iostream>
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     7
#include <fstream>
28
54addf5893ef cstdlib declares EXIT_SUCCESS and EXIT_FAILURE in c++
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 11
diff changeset
     8
#include <cstdlib>
11
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     9
29
7abf6146898e indent -bad changed to -nbad:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 28
diff changeset
    10
int main (int argc, char **argv)
11
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    11
{
29
7abf6146898e indent -bad changed to -nbad:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 28
diff changeset
    12
    std::ifstream in;
7abf6146898e indent -bad changed to -nbad:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 28
diff changeset
    13
    std::ofstream out;
11
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    14
29
7abf6146898e indent -bad changed to -nbad:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 28
diff changeset
    15
    char c;
11
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    16
29
7abf6146898e indent -bad changed to -nbad:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 28
diff changeset
    17
    if (argc != 3) {
7abf6146898e indent -bad changed to -nbad:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 28
diff changeset
    18
        std::cout << "Benutzung: " << argv[0] << " <datei> <datei>" << std::endl;
7abf6146898e indent -bad changed to -nbad:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 28
diff changeset
    19
        return EXIT_SUCCESS;
7abf6146898e indent -bad changed to -nbad:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 28
diff changeset
    20
    }
11
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    21
29
7abf6146898e indent -bad changed to -nbad:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 28
diff changeset
    22
    in.open (argv[1], std::ios::binary);
7abf6146898e indent -bad changed to -nbad:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 28
diff changeset
    23
    if (!in) {
7abf6146898e indent -bad changed to -nbad:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 28
diff changeset
    24
        std::cerr << "Fehler: Kann Datei " << argv[1] << " nicht lesen!" << std::endl;
7abf6146898e indent -bad changed to -nbad:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 28
diff changeset
    25
    }
11
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    26
29
7abf6146898e indent -bad changed to -nbad:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 28
diff changeset
    27
    out.open (argv[2]);
7abf6146898e indent -bad changed to -nbad:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 28
diff changeset
    28
    if (!out) {
7abf6146898e indent -bad changed to -nbad:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 28
diff changeset
    29
        std::cerr << "Fehler: Kann Datei " << argv[2] << " nicht beschreiben!" << std::endl;
7abf6146898e indent -bad changed to -nbad:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 28
diff changeset
    30
    }
11
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    31
29
7abf6146898e indent -bad changed to -nbad:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 28
diff changeset
    32
    while (in.get (c)) {
7abf6146898e indent -bad changed to -nbad:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 28
diff changeset
    33
        out << c;
7abf6146898e indent -bad changed to -nbad:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 28
diff changeset
    34
    }
11
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    35
29
7abf6146898e indent -bad changed to -nbad:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 28
diff changeset
    36
    in.close ();
7abf6146898e indent -bad changed to -nbad:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 28
diff changeset
    37
    out.close ();
11
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    38
29
7abf6146898e indent -bad changed to -nbad:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 28
diff changeset
    39
    return EXIT_SUCCESS;
11
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    40
}