// OpenFile.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "windows.h" #include "iostream" #include "stdio.h" #include using namespace std; int _tmain(int argc, _TCHAR* argv[]) { ifstream in ("C:\\work\\abc.dat", ios_base::binary); ofstream out ("C:\\work\\def.dat", ios_base::binary); if (in.good() && out.good ()) { bool finished = false; while (! finished) { const int step = 16*1024; char data [step]; in.read (data, step); streamsize result = in.gcount(); if (result != 0) out.write (data, result); else finished = true; cout << "Data zapsana " << result << endl; } } in.close (); out.close (); #if 0 // 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_ALWAYS, // how to create FILE_ATTRIBUTE_NORMAL, // file attributes NULL // handle to file with attributes to copy ); if (src == INVALID_HANDLE_VALUE) std::cout << "Nelze otevrit zdrojovy soubor" << std::endl; if (dst == INVALID_HANDLE_VALUE) std::cout << "Nelze otevrit cilovy soubor" << std::endl; 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 finished = false; while (! finished) { BOOL ok = ReadFile (src, data, step, &result, NULL); if (! ok) std::cout << "Chyba pri cteni" << std::endl; 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 " << answer << std::endl; else std::cout << "Chyba pri zapisu" << std::endl; } else { finished = true; } } } if (src != INVALID_HANDLE_VALUE) CloseHandle (src); if (dst != INVALID_HANDLE_VALUE) CloseHandle (dst); #endif // int wait; // std::cout.flush(); // std::cin >> wait; std::cout << "Konec programu" << std::endl; char * str = new char [11]; std::cin.read(str, 10); return 0; }