Advertisement
Specowy

Untitled

May 1st, 2020
610
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. using namespace std;
  5. bool wyswietl(string sNazwaPliku )
  6. {
  7.     ifstream plik;
  8.     plik.open( sNazwaPliku.c_str() );
  9.     if( !plik.good() )
  10.          return false;
  11.    
  12.     std::string wiersz;
  13.     while( std::getline( plik, wiersz ) )
  14.          std::cout << wiersz << std::endl;
  15.    
  16.     plik.close();
  17.     return true;
  18. }
  19.  
  20. int main()
  21. { ofstream plik( "tekst.txt" );
  22.     plik << "tekst pliku";
  23.     plik.close();
  24.  
  25.     if( !wyswietl( "tekst.txt" ) )
  26.          std::cout << "Nie udalo sie otworzyc pliku o podanej nazwie." << std::endl;
  27.    
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement