-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWriteFileBlock.cpp
More file actions
27 lines (24 loc) · 840 Bytes
/
Copy pathWriteFileBlock.cpp
File metadata and controls
27 lines (24 loc) · 840 Bytes
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
#include <stdexcept>
#include <fstream>
#include "WriteFileBlock.h"
#include "BlockMaker.h"
static BlockMaker<WriteFileBlock> maker("writefile");
std::list<std::string>& WriteFileBlock::execute(const std::list<std::string>& params, std::list<std::string>& text) {
if (params.size() != 1) {
throw IncorrectAmountOfParams("Writeblock needs only one param, given "
+ std::to_string(params.size()));
}
std::string filename = params.back();
std::ofstream file;
try {
file.open(filename, std::ios::out);
}
catch (std::exception& exception) {
throw FileDoesNotExistException("File " + filename + "doesnt exist");
}
for (auto it = text.begin(); it != text.end(); ++it) {
file << *it << std::endl;
}
file.close();
return text;
}