Advertisement
KAYOver

Untitled

Sep 10th, 2021
956
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.41 KB | None | 0 0
  1. #include <iostream>
  2. #include <windows.h>
  3.  
  4. char in[255] = "E:\\in.txt";
  5. char out[255] = "E:\\out.txt";
  6. char readed[255] = "";
  7.  
  8. void read()
  9. {
  10.     HANDLE hFile = CreateFile(
  11.         in,
  12.         GENERIC_READ,
  13.         FILE_SHARE_READ,
  14.         NULL,
  15.         OPEN_EXISTING,
  16.         FILE_ATTRIBUTE_NORMAL,
  17.         NULL
  18.     );
  19.     DWORD dwBytes = 0;
  20.    
  21.     if(hFile < 0)
  22.     {
  23.         std::cout << "Не получилось открыть вводной файл!" << std::endl;
  24.         exit(-1);
  25.     }
  26.  
  27.     ReadFile(hFile, readed, GetFileSize(hFile, NULL), &dwBytes, NULL);
  28.     std::cout << "Вводной файл прочитан." << std::endl;
  29.     std::cout << "Содержимое вводного файла: " << readed << std::endl;
  30.     CloseHandle(hFile);
  31. }
  32.  
  33. void write()
  34. {
  35.     HANDLE hFile = CreateFile(
  36.         out,
  37.         GENERIC_WRITE,
  38.         FILE_SHARE_WRITE,
  39.         NULL,
  40.         CREATE_ALWAYS,
  41.         FILE_ATTRIBUTE_NORMAL,
  42.         NULL
  43.     );
  44.     DWORD dwBytes = 0;
  45.  
  46.     if (hFile < 0)
  47.     {
  48.         std::cout << "Не получилось открыть выводной файл!" << std::endl;
  49.         exit(-1);
  50.     }
  51.  
  52.     WriteFile(hFile, readed, strlen(readed), &dwBytes, NULL);
  53.     std::cout << "Выводной файл записан" << std::endl;
  54.     CloseHandle(hFile);
  55. }
  56.  
  57. int main()
  58. {
  59.     read();
  60.     write();
  61.     DeleteFile(in);
  62.     std::cin.get();
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement