C++ (Qt) |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
| // upr3.cpp: определяет точку входа для консольного приложения.
//
#include "stdafx.h"
#include<fstream>
#include<iostream>
#include<string>
#include<cstdlib>
int main(int argc, char *argv[])
{
using namespace std;
string ch,chtmp;
if (argc == 1)
{
cerr << "Usage; " << argv[0] << " filename[s]\n";
exit(EXIT_FAILURE);
}
cout << "Copy in file a to file b\n";
for (int i = 1; i < argc; i++)
{
if (i == 1)
{
ifstream file_in(argv[i]);
cout << "Open file filenames[s]\n";
if (!file_in.is_open())
{
cout << "Error not open filename[s]" << endl;
file_in.clear();
}
else
{
cout << "Read file filenames[s]\n";
while (getline(file_in,ch)&&ch.size()>0)
{
cout<<ch<<endl;
chtmp += ch;
chtmp += '\n';
}
cout << "Close file filenames[s]\n";
file_in.close();
file_in.clear();
}
}
else if(i==2)
{
ofstream file_out(argv[i], ios::out | ios::app);
cout << "Open file filenames[s]\n";
if (!file_out.is_open())
{
cout << "Error not open filename[s]" << endl;
file_out.clear();
}
else
{
cout << "Write file filenames[s]\n";
file_out << chtmp << endl;
cout << "Close file filenames[s]\n";
file_out.close();
file_out.clear();
}
}
else
{
cout << "Errors big errors\n";
}
}
//Открытие файлов а и б
//Проверить открылись ли файлы
//Прочитать файл а
//Сохранить данные в файл б
//Проверить файл б
system("pause");
return 0;
} |
|
Пришлось сделать ещё одну строку так как первая очищалась после прочтения (почему то)