// 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 f; f = 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 (f == INVALID_HANDLE_VALUE) std::cout << "Nejde otevrit" << std::endl; else { std::cout << "Soubor otevren" << std::endl; char data [] = "Nejaky text \r\n Dalsi radka"; DWORD size = strlen (data); DWORD result; BOOL ok; ok = WriteFile (f, // handle data, // pointer to data size, // number of bytes & result, NULL); if (ok && result == size) std::cout << "Data zapsana" << std::endl; else std::cout << "Chyba pri zapisu" << std::endl; CloseHandle (f); } // int wait; // std::cout.flush(); // std::cin >> wait; char * str = new char [11]; std::cin.read(str, 10); return 0; }