Advertisement
RobertDeMilo

WB4.5 Аккуратное создание потока

Oct 11th, 2023
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     ifstream input("C:/Users/musta/Downloads/text.txt");
  9.     string line;
  10.    
  11.     //if (input.is_open()) или
  12.     if (input)
  13.     {
  14.         while (getline(input, line))
  15.         {
  16.             cout << line << endl;
  17.         }
  18.         cout << "done!" << endl;
  19.     }
  20.     else
  21.     {
  22.         cout << "error!" << endl;
  23.     }
  24.     // (файловые) потоки можно приводить к типу bool и вернут true, если с ними можно работать в данный момент
  25.  
  26.     return 0;
  27. }
Tags: is_open
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement