title: ReadFile Win32 API
body: <p>i want to read a file.. but.. when i debug my program it runs but a pop up appears and says system programming has stopped working and in the console, it`s written that Press enter to close the program. my code is ::</p>
  
  <pre><code>// System Programming.cpp : Defines the entry point for the console application.
  //
  
  #include "stdafx.h"
  #include "iostream"
  using namespace std;
  
  int _tmain(int argc, _TCHAR* argv[])
  {
      HANDLE hin;
      HANDLE hout;
      TCHAR buff[20]= {'q','2','3'};
      TCHAR buff2[20]={'a','v'};
      hin = CreateFile(_T("Abid.txt"),GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
      if(hin == INVALID_HANDLE_VALUE)
      {
          cout&lt;&lt;"error";
      }
  
      WriteFile(hin,buff,40,0,NULL);
      CloseHandle(hin);
  
      hout = CreateFile(_T("Abid.txt"),GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
  
      if(hout == INVALID_HANDLE_VALUE)
      {
          cout&lt;&lt;"error";
      }
  
      ReadFile(hout,buff2,40,0,NULL);
      CloseHandle(hout);
      return 0;
  }
  </code></pre>