Petro_zzz

0211_file_like_C

Nov 2nd, 2022
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. void save_to_file() {
  4.     FILE* pf;
  5.     if (fopen_s(&pf, "2.txt", "a")) {
  6.         fprintf(pf, "%s", "Hello. This is my file3.");
  7.         fclose(pf);
  8.         delete pf;
  9.     }
  10. }
  11.  
  12. void main() {
  13.     FILE* pf;
  14.     char buff[200];
  15.     fopen_s(&pf, "2.txt", "r");
  16.     while (!feof(pf)) {
  17.         fscanf_s(pf, "%s ", buff, sizeof(buff));
  18.         std::cout << buff; // c++ стиль
  19.     }
  20.     fclose(pf);
  21.     delete pf;
  22.    
  23.  
  24. }
Advertisement
Add Comment
Please, Sign In to add comment