// OpenFile.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "windows.h" #include "iostream" #include "stdio.h" int _tmain(int argc, _TCHAR* argv[]) { // printf ("Opening file\n"); HANDLE src; src = CreateFile ( "C:\\work\\abc.dat", // pointer to name of the file GENERIC_READ, // access (read-write) mode 0, // share mode NULL, // pointer to security attributes OPEN_EXISTING, // how to create FILE_ATTRIBUTE_NORMAL, // file attributes NULL // handle to file with attributes to copy ); HANDLE dst; dst = CreateFile ( "C:\\work\\def.dat", // pointer to name of the file GENERIC_WRITE, // access (read-write) mode 0, // share mode NULL, // pointer to security attributes CREATE_NEW, // how to create FILE_ATTRIBUTE_NORMAL, // file attributes NULL // handle to file with attributes to copy ); if (src != INVALID_HANDLE_VALUE && dst != INVALID_HANDLE_VALUE) { std::cout << "Soubory otevreny" << std::endl; const int step = 16*1024; char data [step]; DWORD result; BOOL ok = ReadFile (src, data, step, &result, NULL); if (ok && result != 0) { DWORD answer; ok = WriteFile (dst, // handle data, // pointer to data result, // number of bytes & answer, NULL); if (ok && result == answer) std::cout << "Data zapsana" << std::endl; else std::cout << "Chyba pri zapisu" << std::endl; } CloseHandle (src); CloseHandle (dst); } // int wait; // std::cout.flush(); // std::cin >> wait; char * str = new char [11]; std::cin.read(str, 10); return 0; }