Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.55 KB | None | 0 0
  1. //5.uloha
  2. void clearBuff(string buff[], int count) {
  3.     for (int i = 0; i < count; i++) {
  4.         buff[i] = "";
  5.     }
  6. }
  7.  
  8. string replaceIt(string line) {
  9.     string new_string = "";
  10.  
  11.     for (int i = 0; i < line.size(); i++) {
  12.         new_string += line[i];
  13.     }
  14.  
  15.     return new_string;
  16. }
  17.  
  18. string fixLine(string line) {
  19.     string new_string;
  20.     int index = line.size();
  21.     switch (line[index]) {
  22.     case '\n':
  23.         new_string = replaceIt(line);
  24.         return new_string;
  25.     case '\r':
  26.         new_string = replaceIt(line);
  27.         return new_string;
  28.     case '\t':
  29.         new_string = replaceIt(line);
  30.         return new_string;
  31.     case '\b':
  32.         new_string = replaceIt(line);
  33.         return new_string;
  34.     case '\v':
  35.         new_string = replaceIt(line);
  36.         return new_string;
  37.     case '\0':
  38.         new_string = replaceIt(line);
  39.         return new_string;
  40.     default:
  41.         return line;
  42.         break;
  43.     }
  44. }
  45. bool Titulky::nacitajZoSuboru(const string &menoSuboru) {
  46.     string buffer[200];
  47.  
  48.     short loop = 0; //short for loop for input
  49.  
  50.     string line; //this will contain the data read from the file
  51.  
  52.     ifstream myfile(menoSuboru); //opening the file.
  53.  
  54.     if (myfile) //if the file is open
  55.     {
  56.         while (getline(myfile, line)) //while the end of file is NOT reached
  57.         {
  58.  
  59.             if (line == "") {
  60.                 try {
  61.                     vlozTitulok(buffer, loop);
  62.                 }
  63.                 catch (ZlyVstup) {
  64.                 }
  65.                 clearBuff(buffer, loop);
  66.                 loop = 0;
  67.             }
  68.             else if (loop > 1) {
  69.                 buffer[loop] = fixLine(line);
  70.                 loop++;
  71.             }
  72.             else {
  73.                 buffer[loop] = line;
  74.                 loop++;
  75.             }
  76.         }
  77.         myfile.close(); //closing the file
  78.     }
  79.     else {
  80.         return false;
  81.     }
  82.     return true;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement