@xtorne21st
интересующийся
304 / 275 / 19
Регистрация: 25.09.2010
Сообщений: 1,056
|
09.05.2013, 01:06
|
|
C++ | 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
| #include <vector>
#include <string>
#include <iostream>
#include <fstream>
#include <iterator>
#define FLUSH_CIN if (std::wcin.peek()) std::wcin.ignore()
int main(int argc, const char* argv[])
{
if (argc != 2)
{
std::cerr << "wrong arguments" << std::endl;
return 1;
}
std::locale::global(std::locale(""));
std::wstring in_word, out_word;
std::wcout << L"Найти слово: ";
std::wcin >> in_word;
FLUSH_CIN;
std::wcout << L"Заменить на слово: ";
std::getline(std::wcin, out_word);
std::wifstream in(argv[1], std::ios::in);
if (!in.good())
{
std::cerr << "couldn't open file '" << argv[1] << "'\n";
return 1;
}
std::istream_iterator<std::wstring, wchar_t> ii(in);
std::istream_iterator<std::wstring, wchar_t> eos;
std::vector<std::wstring> fileInside(ii, eos);
in.close();
for (int i = 0; i < fileInside.size(); ++i)
{
if (fileInside[i] == in_word)
{
fileInside[i] = out_word;
}
}
std::wofstream out(argv[1], std::ios::out | std::ios::trunc);
if (!out.good())
{
std::cerr << "couldn't open file '" << argv[1] << "'\n";
return 1;
}
for (int i = 0; i < fileInside.size(); ++i)
{
out << fileInside[i] << std::endl;
}
out.close();
return 0;
} |
|
1
|