Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cassert>
- #include <fstream>
- #include <iostream>
- #include <string>
- #include <string_view>
- using namespace std;
- void CreateFiles(const string& config_file) {
- using namespace literals;
- ifstream input(config_file);
- ofstream output;
- for (std::string line; std::getline(input, line); ) {
- if (line[0] == '>') {
- output << line.substr(1, line.string::npos) << endl;
- } else {
- output.close();
- output.open(line);
- }
- }
- }
- string GetLine(istream& in) {
- string s;
- getline(in, s);
- return s;
- }
- int main() {
- ofstream("test_config.txt"s) << "a.txt\n"
- ">10\n"
- ">abc\n"
- "b.txt\n"
- ">123"sv;
- CreateFiles("test_config.txt"s);
- ifstream in_a("a.txt"s);
- assert(GetLine(in_a) == "10"s && GetLine(in_a) == "abc"s);
- ifstream in_b("b.txt"s);
- assert(GetLine(in_b) == "123"s);
- }
Advertisement
Add Comment
Please, Sign In to add comment