-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfcreate.cpp
More file actions
62 lines (42 loc) · 1.52 KB
/
Copy pathfcreate.cpp
File metadata and controls
62 lines (42 loc) · 1.52 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
58
59
60
61
62
#include <iostream>
#include <string>
#include <fstream>
#include <filesystem>
int main() {
std::ofstream headerFile;
std::ofstream implFile;
std::string fileName;
std::string header = "src/Header/";
std::string implementation = "src/Implementation/";
std::cout << "Enter your file name:" << std::endl;
std::cout << "=>";
getline(std::cin, fileName);
if (fileName.empty()) {
std::cout << "Empty file name" << std::endl;
return 1;
}
if (std::filesystem::exists(header + fileName + ".h") ||
std::filesystem::exists(implementation + fileName + ".cpp")) {
std::cout << "File already exists" << std::endl;
return 1;
}
headerFile.open(header + fileName + ".h", std::ios::app);
implFile.open(implementation + fileName + ".cpp", std::ios::app);
if (!headerFile.is_open() || !implFile.is_open()) {
std::cout << "Failed to create file!" << std::endl;
return 1;
}
//header
headerFile << "#include " << "<string>" << std::endl;
headerFile << "#include " << "<fstream>" << std::endl;
headerFile << "\n\n" << std::endl;
headerFile << "class " + fileName + "{\n\n};" << std::endl;
//implementation
implFile << "#include \"" << fileName << ".h\"" << std::endl;
implFile << "#include " << "<string>" << std::endl;
implFile << "#include " << "<filesystem>" << std::endl;
std::cout << "File created successfully!" << std::endl;
headerFile.close();
implFile.close();
return 0;
}//fun end