IIIa66uMEM6eP,
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
| #include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <stdexcept>
void copy_file(const std::string& src, const std::string& dst, bool rw = true)
{
std::ifstream in(src.c_str(), std::ios::binary);
if ( !in )
{
throw std::runtime_error("can`t open file: " + src);
}
std::ofstream out(dst.c_str(), (std::ios::binary|((rw)?std::ios::trunc:std::ios::binary)));
if ( !out )
{
throw std::runtime_error("can`t create file: " + dst);
}
out << in.rdbuf();
}
int main()
{
const std::string &file_name("diff.exe");
std::vector<std::string> vec = {"path_1, path_2, path_3"};
for(size_t i = 0; i < vec.size(); ++i)
{
vec[i] += file_name;
try
{
copy_file("E:\\diff.exe", vec[i]);
} catch (const std::exception& e)
{
std::cout << e.what() << std::endl;
}
}
return 0;
} |
|
Вектор заполните иным способом, так как я зделал это в стиле С++0x, что проканает только на GCC4.5+