Advertisement
Guest User

Untitled

a guest
Sep 24th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.84 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <fstream>
  4. #include <string>
  5.  
  6. using namespace std;
  7. int main()
  8. {
  9.     string tresc = "";
  10.     int il_zn = 0;
  11.     int il_wyr = 0;
  12.     int linijka = 0;
  13.     string najkr = "";
  14.     string najdl = "";
  15.     int mini = 5;
  16.     int maxi = 0;
  17.  
  18.  
  19.     ifstream plik("C:\\Users\\Veasst\\Desktop\\test.txt", ifstream::binary);
  20.     if (plik.is_open())
  21.     {
  22.         while (!plik.eof())
  23.         {
  24.             getline(plik, tresc);
  25.             linijka++;
  26.         }
  27.  
  28.         cout << "Ilosc linijek: " << linijka << endl;
  29.     }
  30.  
  31.     plik.open("C:\\Users\\Veasst\\Desktop\\test.txt", ifstream::binary);
  32.     if (plik.is_open()) {
  33.         plik.clear();
  34.         plik.seekg(0, std::ios::beg);
  35.         {
  36.             while (!plik.eof())
  37.             {
  38.                 plik >> tresc;
  39.                 il_wyr++;
  40.                 int temp2 = tresc.length();
  41.  
  42.                 if (temp2 > maxi)
  43.                 {
  44.                     maxi = temp2;
  45.                     najdl = tresc;
  46.                 }
  47.  
  48.                 if (temp2 < mini&&temp2 != 0)
  49.                 {
  50.  
  51.                     mini = temp2;
  52.                     najkr = tresc;
  53.  
  54.                 }
  55.             }
  56.         }
  57.  
  58.         cout << il_wyr << " wyrazuf" << endl;
  59.         cout << "Najdluzszy: " << najdl << endl;
  60.         cout << "Najkrotszy: " << najkr << endl;
  61.  
  62.  
  63.         plik.close();
  64.         plik.open("C:\\Users\\Veasst\\Desktop\\test.txt", ifstream::binary);
  65.         if (plik.is_open()) {
  66.             plik.seekg(0, std::ios::end);
  67.             il_zn = plik.tellg();
  68.             plik.seekg(0, std::ios::beg);
  69.  
  70.             cout << il_zn << " znakuf" << endl;
  71.         }
  72.  
  73.         plik.close();
  74.         plik.open("C:\\Users\\Veasst\\Desktop\\test.txt", ifstream::binary);
  75.         if (plik.is_open()) {
  76.             char* odwrocony_tekst = new char[il_zn];
  77.             char* tekst = new char[il_zn];
  78.  
  79.             plik.read(tekst, il_zn);
  80.             tekst[il_zn] = 0;
  81.             plik.close();
  82.  
  83.             for (int i = 0;i < il_zn;i++)
  84.             {
  85.                 odwrocony_tekst[i] = tekst[il_zn - i - 1];
  86.             }
  87.  
  88.             ofstream zapis("C:\\Users\\Veasst\\Desktop\\potato.txt", ofstream::binary);
  89.  
  90.             zapis.write(odwrocony_tekst, il_zn);
  91.  
  92.             zapis.close();
  93.         }
  94.     }
  95.  
  96.     system("pause");
  97.     return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement