Advertisement
MeehoweCK

Untitled

May 16th, 2024
645
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. std::string odwrocenie(const std::string& slowo) {
  5.     std::string result{};
  6.     for (auto i{ static_cast<int>(slowo.size() - 1) }; i >= 0; --i) {
  7.         result += slowo[i];
  8.     }
  9.     return result;
  10. }
  11.  
  12. void odczytaj_i_zapisz() {
  13.     std::ifstream plik{ "tekst.txt" };
  14.     if (plik.fail()) {
  15.         std::cout << "Blad odczytu!\n";
  16.         return;
  17.     }
  18.     std::string slowo;
  19.     while (plik >> slowo) {
  20.         std::cout << odwrocenie(slowo) << ' ';
  21.     }
  22.     plik.close();
  23.     std::cout << std::endl;
  24.  
  25. }
  26.  
  27. int main() {
  28.     odczytaj_i_zapisz();
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement