author | Markus Bröker<broeker.markus@googlemail.com> |
Sun, 10 Feb 2019 13:17:01 +0100 | |
changeset 173 | 374a86886bc5 |
parent 77 | 49e0babccb23 |
permissions | -rw-r--r-- |
11
0a8be4eac87e
c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
1 |
/** |
77 | 2 |
* copy.cc |
3 |
* Copyright (C) 2008 Markus Bröker |
|
4 |
* |
|
11
0a8be4eac87e
c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
5 |
* Kopierprogramm für Dateien in C++ |
0a8be4eac87e
c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
6 |
*/ |
0a8be4eac87e
c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
7 |
|
0a8be4eac87e
c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
8 |
#include <iostream> |
0a8be4eac87e
c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
9 |
#include <fstream> |
28
54addf5893ef
cstdlib declares EXIT_SUCCESS and EXIT_FAILURE in c++
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
11
diff
changeset
|
10 |
#include <cstdlib> |
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 |
int main (int argc, char **argv) |
11
0a8be4eac87e
c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
13 |
{ |
29
7abf6146898e
indent -bad changed to -nbad:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
28
diff
changeset
|
14 |
std::ifstream in; |
7abf6146898e
indent -bad changed to -nbad:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
28
diff
changeset
|
15 |
std::ofstream out; |
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 |
char c; |
11
0a8be4eac87e
c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
18 |
|
29
7abf6146898e
indent -bad changed to -nbad:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
28
diff
changeset
|
19 |
if (argc != 3) { |
63
5a82f89d607e
uint vs size_t and two bugfixes in fak and unicode
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
29
diff
changeset
|
20 |
std::cout << "Benutzung: " << argv[0] << " <QUELLE> <ZIEL>" << std::endl; |
29
7abf6146898e
indent -bad changed to -nbad:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
28
diff
changeset
|
21 |
return EXIT_SUCCESS; |
7abf6146898e
indent -bad changed to -nbad:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
28
diff
changeset
|
22 |
} |
11
0a8be4eac87e
c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
23 |
|
29
7abf6146898e
indent -bad changed to -nbad:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
28
diff
changeset
|
24 |
in.open (argv[1], std::ios::binary); |
7abf6146898e
indent -bad changed to -nbad:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
28
diff
changeset
|
25 |
if (!in) { |
7abf6146898e
indent -bad changed to -nbad:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
28
diff
changeset
|
26 |
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
|
27 |
} |
11
0a8be4eac87e
c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
28 |
|
29
7abf6146898e
indent -bad changed to -nbad:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
28
diff
changeset
|
29 |
out.open (argv[2]); |
7abf6146898e
indent -bad changed to -nbad:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
28
diff
changeset
|
30 |
if (!out) { |
7abf6146898e
indent -bad changed to -nbad:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
28
diff
changeset
|
31 |
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
|
32 |
} |
11
0a8be4eac87e
c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
33 |
|
29
7abf6146898e
indent -bad changed to -nbad:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
28
diff
changeset
|
34 |
while (in.get (c)) { |
7abf6146898e
indent -bad changed to -nbad:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
28
diff
changeset
|
35 |
out << c; |
7abf6146898e
indent -bad changed to -nbad:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
28
diff
changeset
|
36 |
} |
11
0a8be4eac87e
c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
37 |
|
29
7abf6146898e
indent -bad changed to -nbad:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
28
diff
changeset
|
38 |
in.close (); |
7abf6146898e
indent -bad changed to -nbad:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
28
diff
changeset
|
39 |
out.close (); |
11
0a8be4eac87e
c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
40 |
|
29
7abf6146898e
indent -bad changed to -nbad:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
28
diff
changeset
|
41 |
return EXIT_SUCCESS; |
11
0a8be4eac87e
c++ file copy demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
42 |
} |