Advertisement
MeehoweCK

Untitled

May 26th, 2023
762
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <fstream>      // file stream
  2. #include <iostream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     ifstream plik;          // plik tylko do odczytu
  10.     plik.open("plik.txt");      // otwarcie pliku
  11.     if (plik.fail())                    // .fail() zwraca true jeśli plik nie został otwarty
  12.     {
  13.         cout << "Nie udalo sie otworzyc pliku :( \n";
  14.         return 0;
  15.     }
  16.     string tekst;
  17.     //plik >> tekst;        // pobranie do pierwszgo białego znaku (np. spacji)
  18.  
  19.     //while (!plik.eof())       // eof - end of file
  20.     //{
  21.     //  plik >> tekst;
  22.     //  cout << tekst << ' ';
  23.     //}
  24.  
  25.     /*while (plik >> tekst)
  26.     {
  27.         cout << tekst << ' ';
  28.     }*/
  29.  
  30.     // zczytywanie całego wiersza:
  31.     getline(plik, tekst);
  32.     cout << tekst;
  33.  
  34.     plik.close();
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement