fork download
  1. void kompresja(const std::string nazwa_pliku, const int r_wej, const int r_his, std::string& tekst)
  2. {
  3. std::cout << "Wielkosc pliku przed kompresja wynosi " << 8 * tekst.length() << " bitow" << std::endl;
  4. int bity_pliku_wyj{ 8 };
  5. int bity_his {ile_bitow(r_his)};
  6. std::cout << bity_his << std::endl;
  7. std::ofstream plik(nazwa_pliku);
  8. plik << tekst[0];
  9. std::string chwilowy(r_his, tekst[0]);
  10. tekst.insert(0, chwilowy);
  11. int wsk_his{0};
  12. int wsk_wej{r_his};
  13. for (int wsk_wej = r_his; wsk_wej < tekst.length();)
  14. {
  15. int C{}, P{}, C_max{};
  16. for (int k = wsk_his; k < wsk_his + r_his && k < tekst.length(); k++)
  17. if (tekst[wsk_wej] == tekst[k])
  18. {
  19. C = 1;
  20. while ( (tekst[wsk_wej + C] == tekst[k + C]) && (wsk_wej + C < tekst.length()) && (C < r_wej) && (C < r_his))
  21. if ((wsk_wej+C < tekst.length()) && (k+C < tekst.length()))
  22. C++;
  23. if (C > C_max)
  24. {
  25. C_max = C;
  26. P = k - wsk_his;
  27. }
  28. }
  29. if ((C_max == 0) or (bity_his + bity_his > 8 * C_max))
  30. {
  31. bity_pliku_wyj += 9;
  32. plik << '1' << tekst[wsk_wej] << std::endl;
  33. wsk_his += 1;
  34. wsk_wej += 1;
  35. }
  36. else
  37. {
  38. bity_pliku_wyj += 1 + bity_his + bity_his;
  39. plik << '0' << P << C_max << std::endl;
  40. wsk_his += C_max;
  41. wsk_wej += C_max;
  42. }
  43.  
  44.  
  45. }
  46. std::cout << "Wielkosc pliku po kompresji wynosi " << bity_pliku_wyj << " bitow" << std::endl;
  47. plik.close();
  48. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:27: error: ‘string’ in namespace ‘std’ does not name a type
 void kompresja(const std::string nazwa_pliku, const int r_wej, const int r_his, std::string& tekst)
                           ^~~~~~
prog.cpp:1:22: note: ‘std::string’ is defined in header ‘<string>’; did you forget to ‘#include <string>’?
+#include <string>
 void kompresja(const std::string nazwa_pliku, const int r_wej, const int r_his, std::string& tekst)
                      ^~~
prog.cpp:1:86: error: ‘std::string’ has not been declared
 void kompresja(const std::string nazwa_pliku, const int r_wej, const int r_his, std::string& tekst)
                                                                                      ^~~~~~
prog.cpp: In function ‘void kompresja(int, int, int, int&)’:
prog.cpp:3:7: error: ‘cout’ is not a member of ‘std’
  std::cout << "Wielkosc pliku przed kompresja wynosi " << 8 * tekst.length() << " bitow" << std::endl;
       ^~~~
prog.cpp:3:7: note: ‘std::cout’ is defined in header ‘<iostream>’; did you forget to ‘#include <iostream>’?
prog.cpp:1:1:
+#include <iostream>
 void kompresja(const std::string nazwa_pliku, const int r_wej, const int r_his, std::string& tekst)
prog.cpp:3:7:
  std::cout << "Wielkosc pliku przed kompresja wynosi " << 8 * tekst.length() << " bitow" << std::endl;
       ^~~~
prog.cpp:3:69: error: request for member ‘length’ in ‘tekst’, which is of non-class type ‘int’
  std::cout << "Wielkosc pliku przed kompresja wynosi " << 8 * tekst.length() << " bitow" << std::endl;
                                                                     ^~~~~~
prog.cpp:3:98: error: ‘endl’ is not a member of ‘std’
  std::cout << "Wielkosc pliku przed kompresja wynosi " << 8 * tekst.length() << " bitow" << std::endl;
                                                                                                  ^~~~
prog.cpp:3:98: note: ‘std::endl’ is defined in header ‘<ostream>’; did you forget to ‘#include <ostream>’?
prog.cpp:1:1:
+#include <ostream>
 void kompresja(const std::string nazwa_pliku, const int r_wej, const int r_his, std::string& tekst)
prog.cpp:3:98:
  std::cout << "Wielkosc pliku przed kompresja wynosi " << 8 * tekst.length() << " bitow" << std::endl;
                                                                                                  ^~~~
prog.cpp:5:16: error: ‘ile_bitow’ was not declared in this scope
  int bity_his {ile_bitow(r_his)};
                ^~~~~~~~~
prog.cpp:6:7: error: ‘cout’ is not a member of ‘std’
  std::cout << bity_his << std::endl;
       ^~~~
prog.cpp:6:7: note: ‘std::cout’ is defined in header ‘<iostream>’; did you forget to ‘#include <iostream>’?
prog.cpp:6:32: error: ‘endl’ is not a member of ‘std’
  std::cout << bity_his << std::endl;
                                ^~~~
prog.cpp:6:32: note: ‘std::endl’ is defined in header ‘<ostream>’; did you forget to ‘#include <ostream>’?
prog.cpp:7:7: error: ‘ofstream’ is not a member of ‘std’
  std::ofstream plik(nazwa_pliku);
       ^~~~~~~~
prog.cpp:7:7: note: ‘std::ofstream’ is defined in header ‘<fstream>’; did you forget to ‘#include <fstream>’?
prog.cpp:1:1:
+#include <fstream>
 void kompresja(const std::string nazwa_pliku, const int r_wej, const int r_his, std::string& tekst)
prog.cpp:7:7:
  std::ofstream plik(nazwa_pliku);
       ^~~~~~~~
prog.cpp:8:2: error: ‘plik’ was not declared in this scope
  plik << tekst[0];
  ^~~~
prog.cpp:8:17: error: invalid types ‘int[int]’ for array subscript
  plik << tekst[0];
                 ^
prog.cpp:9:7: error: ‘string’ is not a member of ‘std’
  std::string chwilowy(r_his, tekst[0]);
       ^~~~~~
prog.cpp:9:7: note: ‘std::string’ is defined in header ‘<string>’; did you forget to ‘#include <string>’?
prog.cpp:10:8: error: request for member ‘insert’ in ‘tekst’, which is of non-class type ‘int’
  tekst.insert(0, chwilowy);
        ^~~~~~
prog.cpp:10:18: error: ‘chwilowy’ was not declared in this scope
  tekst.insert(0, chwilowy);
                  ^~~~~~~~
prog.cpp:13:44: error: request for member ‘length’ in ‘tekst’, which is of non-class type ‘int’
  for (int wsk_wej = r_his; wsk_wej < tekst.length();)
                                            ^~~~~~
prog.cpp:16:59: error: request for member ‘length’ in ‘tekst’, which is of non-class type ‘int’
    for (int k = wsk_his; k < wsk_his + r_his && k < tekst.length(); k++)
                                                           ^~~~~~
prog.cpp:17:22: error: invalid types ‘int[int]’ for array subscript
     if (tekst[wsk_wej] == tekst[k])
                      ^
prog.cpp:17:34: error: invalid types ‘int[int]’ for array subscript
     if (tekst[wsk_wej] == tekst[k])
                                  ^
prog.cpp:20:33: error: invalid types ‘int[int]’ for array subscript
       while ( (tekst[wsk_wej + C] == tekst[k + C]) && (wsk_wej + C < tekst.length()) && (C < r_wej) && (C < r_his))
                                 ^
prog.cpp:20:49: error: invalid types ‘int[int]’ for array subscript
       while ( (tekst[wsk_wej + C] == tekst[k + C]) && (wsk_wej + C < tekst.length()) && (C < r_wej) && (C < r_his))
                                                 ^
prog.cpp:20:76: error: request for member ‘length’ in ‘tekst’, which is of non-class type ‘int’
       while ( (tekst[wsk_wej + C] == tekst[k + C]) && (wsk_wej + C < tekst.length()) && (C < r_wej) && (C < r_his))
                                                                            ^~~~~~
prog.cpp:21:31: error: request for member ‘length’ in ‘tekst’, which is of non-class type ‘int’
        if ((wsk_wej+C < tekst.length()) && (k+C < tekst.length()))
                               ^~~~~~
prog.cpp:21:57: error: request for member ‘length’ in ‘tekst’, which is of non-class type ‘int’
        if ((wsk_wej+C < tekst.length()) && (k+C < tekst.length()))
                                                         ^~~~~~
prog.cpp:32:32: error: invalid types ‘int[int]’ for array subscript
    plik << '1' << tekst[wsk_wej] << std::endl;
                                ^
prog.cpp:32:42: error: ‘endl’ is not a member of ‘std’
    plik << '1' << tekst[wsk_wej] << std::endl;
                                          ^~~~
prog.cpp:32:42: note: ‘std::endl’ is defined in header ‘<ostream>’; did you forget to ‘#include <ostream>’?
prog.cpp:39:38: error: ‘endl’ is not a member of ‘std’
    plik << '0' << P << C_max << std::endl;
                                      ^~~~
prog.cpp:39:38: note: ‘std::endl’ is defined in header ‘<ostream>’; did you forget to ‘#include <ostream>’?
prog.cpp:46:7: error: ‘cout’ is not a member of ‘std’
  std::cout << "Wielkosc pliku po kompresji wynosi " << bity_pliku_wyj << " bitow" << std::endl;
       ^~~~
prog.cpp:46:7: note: ‘std::cout’ is defined in header ‘<iostream>’; did you forget to ‘#include <iostream>’?
prog.cpp:46:91: error: ‘endl’ is not a member of ‘std’
  std::cout << "Wielkosc pliku po kompresji wynosi " << bity_pliku_wyj << " bitow" << std::endl;
                                                                                           ^~~~
prog.cpp:46:91: note: ‘std::endl’ is defined in header ‘<ostream>’; did you forget to ‘#include <ostream>’?
stdout
Standard output is empty