Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <fstream>
- #include <string>
- using namespace std;
- int main()
- {
- string tresc = "";
- int il_zn = 0;
- int il_wyr = 0;
- int linijka = 0;
- string najkr = "";
- string najdl = "";
- int mini = 5;
- int maxi = 0;
- ifstream plik("C:\\Users\\Veasst\\Desktop\\test.txt", ifstream::binary);
- if (plik.is_open())
- {
- while (!plik.eof())
- {
- getline(plik, tresc);
- linijka++;
- }
- cout << "Ilosc linijek: " << linijka << endl;
- }
- plik.open("C:\\Users\\Veasst\\Desktop\\test.txt", ifstream::binary);
- if (plik.is_open()) {
- plik.clear();
- plik.seekg(0, std::ios::beg);
- {
- while (!plik.eof())
- {
- plik >> tresc;
- il_wyr++;
- int temp2 = tresc.length();
- if (temp2 > maxi)
- {
- maxi = temp2;
- najdl = tresc;
- }
- if (temp2 < mini&&temp2 != 0)
- {
- mini = temp2;
- najkr = tresc;
- }
- }
- }
- cout << il_wyr << " wyrazuf" << endl;
- cout << "Najdluzszy: " << najdl << endl;
- cout << "Najkrotszy: " << najkr << endl;
- plik.close();
- plik.open("C:\\Users\\Veasst\\Desktop\\test.txt", ifstream::binary);
- if (plik.is_open()) {
- plik.seekg(0, std::ios::end);
- il_zn = plik.tellg();
- plik.seekg(0, std::ios::beg);
- cout << il_zn << " znakuf" << endl;
- }
- plik.close();
- plik.open("C:\\Users\\Veasst\\Desktop\\test.txt", ifstream::binary);
- if (plik.is_open()) {
- char* odwrocony_tekst = new char[il_zn];
- char* tekst = new char[il_zn];
- plik.read(tekst, il_zn);
- tekst[il_zn] = 0;
- plik.close();
- for (int i = 0;i < il_zn;i++)
- {
- odwrocony_tekst[i] = tekst[il_zn - i - 1];
- }
- ofstream zapis("C:\\Users\\Veasst\\Desktop\\potato.txt", ofstream::binary);
- zapis.write(odwrocony_tekst, il_zn);
- zapis.close();
- }
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement