forked from fictionalKarma/benchmark-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfileOperations.cpp
52 lines (48 loc) · 1.18 KB
/
fileOperations.cpp
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
#include "fileOperations.hpp"
void FileOperations::createFile(std::string Path , std::string name){
std::string path = Path+"/"+name;
std::cout << path<<"\n";
std::ofstream outputFile(path);
outputFile << "";
outputFile.close();
}
void FileOperations::removeFile(std::string Path , std::string name){
std::string path = Path+"/"+name;
try
{
bool failed = (!std::ifstream(path) ==true);
if ( failed )
throw 10;
else
std::remove(path.c_str());
}
catch ( int e )
{
std::cout << "Error: could not delete file !\n";
}
}
bool FileOperations::check(std::string Path, std::string name){
std::string path = Path+"/"+name;
std::ifstream infile(path);
return infile.good();
}
void FileOperations::writeToFile(std::string Path ,
std::string name ,
std::string textToFile){
std::string path = Path+"/"+name;
std::ofstream out;
try{
bool failed = (!std::ifstream(path) ==true);
if ( failed )
throw 11;
else{
out.open(path, std::ios::app);
out << textToFile<<"\n";
out.close();
}
}
catch ( int e )
{
std::cout << "Error: file does not exists !\n";
}
}