// OpenFile.cpp : Defines the entry point for the console application. // #include #include #include #include #include int _tmain(int argc, _TCHAR* argv[]) { 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_ALWAYS, // 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 << "Soubor otevren" << std::endl; const DWORD size = 64*1024; char buf [size]; DWORD answer; BOOL ok; do { ok = ReadFile (src, buf, size, &answer, NULL); if (ok) { DWORD result; ok = WriteFile (dst, buf, answer, &result, NULL); if (ok && answer != result) ok = FALSE; } } while (answer != 0 && ok); if (! ok) std::cout << "Chyba pri zapisu" << std::endl; else std::cout << "Zapsano" << std::endl; CloseHandle (src); CloseHandle (dst); } char * str = new char [11]; std::cin.getline(str, 10); return 0; }