// 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[]) { HANDLE h; h = CreateFile ( "C:\\work\\abc.dat", // pointer to name of the file GENERIC_READ | 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 (h == INVALID_HANDLE_VALUE) { std::cout << "Chyba pri otvirani" << std::endl; } else { std::cout << "Soubor otevren" << std::endl; char buf [] = "Nejaky text"; DWORD size = strlen (buf); DWORD answer; BOOL ok; // ok = ReadFile (h, buf, size, &answer, NULL); // answer = read (h, buf, size); ok = WriteFile (h, buf, size, &answer, NULL); if (ok && answer == size) std::cout << "Data zapsana" << std::endl; else std::cout << "Chyba pri zapisu" << std::endl; CloseHandle (h); } char * str = new char [11]; std::cin.getline(str, 10); return 0; }