copy.cc
author Markus Bröker <mbroeker@largo.dyndns.tv>
Thu, 16 Apr 2009 12:47:18 +0200
changeset 28 54addf5893ef
parent 11 0a8be4eac87e
child 29 7abf6146898e
permissions -rw-r--r--
cstdlib declares EXIT_SUCCESS and EXIT_FAILURE in c++ 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
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    10
int main(int argc, char **argv)
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    11
{
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    12
	std::ifstream in;
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    13
	std::ofstream out;
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    14
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    15
	char c;
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    16
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    17
	if ( argc != 3 ) {
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    18
		std::cout << "Benutzung: " << argv[0] << " <datei> <datei>" << std::endl;
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    19
		return EXIT_SUCCESS;
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    20
	}
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    21
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    22
	in.open(argv[1], std::ios::binary);
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    23
	if ( !in ) {
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    24
		std::cerr << "Fehler: Kann Datei " << argv[1] << " nicht lesen!" << std::endl;
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    25
	}
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    26
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    27
	out.open(argv[2]);
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    28
	if ( !out ) {
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    29
		std::cerr << "Fehler: Kann Datei " << argv[2] << " nicht beschreiben!" << std::endl;
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    30
	}
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    31
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    32
	while ( in.get(c) ) {
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    33
		out << c;
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    34
	}
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    35
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    36
	in.close();
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    37
	out.close();
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    38
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    39
	return EXIT_SUCCESS;
0a8be4eac87e c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    40
}