-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
57 lines (46 loc) · 1.14 KB
/
main.cpp
File metadata and controls
57 lines (46 loc) · 1.14 KB
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
#include <cstdlib>
#include <exception>
#include <iostream>
#include <stdexcept>
#include <string>
#include <sys/stat.h>
#include <sys/types.h>
#include <utility>
#include <vector>
bool file_exist(const std::string& _filePath)
{
struct stat info;
return stat(_filePath.c_str(), &info) == 0 && !(info.st_mode & S_IFDIR);
}
std::vector<std::string> get_files_paths(int _argc, char const* _argv[])
{
std::vector<std::string> paths;
std::string path;
for (int i = 1; i < _argc; i++)
{
path = _argv[i];
if (!file_exist(path))
throw std::runtime_error("error : cannot open \"" + path + "\"");
paths.push_back(path);
}
return paths;
}
// command : meta-cxx *.cpp
// g++ [METAFILES] -o program(.exe)
int main(int _argc, char const* _argv[])
{
try
{
const std::vector<std::string>& paths = get_files_paths(_argc, _argv);
for (size_t i = 0; i < paths.size(); i++)
{
std::cout << "path : " + paths[i] << std::endl;
}
}
catch (const std::exception& e)
{
std::cerr << e.what() << '\n';
}
system("pause");
return 0;
}