shushus

Спринт 12. Такие разные потоки.

Apr 6th, 2023
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include <cassert>
  2. #include <fstream>
  3. #include <iostream>
  4. #include <string>
  5. #include <string_view>
  6.  
  7. using namespace std;
  8.  
  9. void CreateFiles(const string& config_file) {
  10.     using namespace literals;
  11.    
  12.     ifstream input(config_file);
  13.     ofstream output;
  14.    
  15.     for (std::string line; std::getline(input, line); ) {
  16.         if (line[0] == '>') {
  17.             output << line.substr(1, line.string::npos) << endl;
  18.         } else {
  19.             output.close();
  20.             output.open(line);
  21.         }
  22.     }
  23. }
  24.  
  25. string GetLine(istream& in) {
  26.     string s;
  27.     getline(in, s);
  28.     return s;
  29. }
  30.  
  31. int main() {
  32.     ofstream("test_config.txt"s) << "a.txt\n"
  33.                                     ">10\n"
  34.                                     ">abc\n"
  35.                                     "b.txt\n"
  36.                                     ">123"sv;
  37.  
  38.     CreateFiles("test_config.txt"s);
  39.     ifstream in_a("a.txt"s);
  40.     assert(GetLine(in_a) == "10"s && GetLine(in_a) == "abc"s);
  41.  
  42.     ifstream in_b("b.txt"s);
  43.     assert(GetLine(in_b) == "123"s);
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment