小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

delphi readline writeln stdout

 quasiceo 2013-12-21
 //標準輸入文件stdin,標準輸出文件stdout,標準錯誤輸出文件stderr,分別得到文件描述符 0, 1, 2

 //創(chuàng)建、寫入、讀取文件。
//蔡軍生 2007/10/21 QQ:9073204 深圳
void CreateFileDemo(void)
{
       //
       HANDLE hFile = ::CreateFile(_T("CreateFileDemo.txt"),     //創(chuàng)建文件的名稱。
             GENERIC_WRITE|GENERIC_READ,          // 寫和讀文件。
             0,                      // 不共享讀寫。
             NULL,                   // 缺省安全屬性。
             CREATE_ALWAYS,          // 如果文件存在,也創(chuàng)建。
             FILE_ATTRIBUTE_NORMAL, // 一般的文件。     
             NULL);                 // 模板文件為空。

       if (hFile == INVALID_HANDLE_VALUE)
       {
             //
             OutputDebugString(_T("CreateFile fail!/r/n"));
       }

       //往文件里寫數據。
       const int BUFSIZE = 4096;
       char chBuffer[BUFSIZE];        
       memcpy(chBuffer,"Test",4);
       DWORD dwWritenSize = 0;
      BOOL bRet = ::WriteFile(hFile,chBuffer,4,&dwWritenSize,NULL);
       if (bRet)
       {
             //
             OutputDebugString(_T("WriteFile 寫文件成功/r/n"));
       }

       //先把寫文件緩沖區(qū)的數據強制寫入磁盤。
       FlushFileBuffers(hFile);

       //
       //從文件里讀取數據。
       LONG lDistance = 0;
       DWORD dwPtr = SetFilePointer(hFile, lDistance, NULL, FILE_BEGIN);
       if (dwPtr == INVALID_SET_FILE_POINTER)
       {
             //獲取出錯碼。
             DWORD dwError = GetLastError() ;
             //處理出錯。          
       }

       DWORD dwReadSize = 0;
      bRet = ::ReadFile(hFile,chBuffer,4,&dwReadSize,NULL);
       if (bRet)
       {
             //
             OutputDebugString(_T("ReadFile 讀文件成功/r/n"));
       }
       else
       {
             //獲取出錯碼。
             DWORD dwError = GetLastError();
             //處理出錯。          
             TCHAR chErrorBuf[1024];
             wsprintf(chErrorBuf,_T("GetLastError()=%d/r/n"),dwError);
             OutputDebugString(chErrorBuf);
       }

}  

procedure write(str:string);                            
  Filestream : integer;                                 
begin                                                   
Filestream := FileCreate(FileName);                     
FileWrite(Filestream ,PCHAR(str)^,length(str)+1);       
end;                                                    
                                                        
procedure writeln(str:string);                          
  Filestream : integer;                                 
begin                                                   
Filestream := FileCreate(FileName);                     
FileWrite(Filestream ,PCHAR(str+chr($a))^,length(str)+1);
end;    


重定向rtl中的Output,然后Writleln就可以向文件輸出了                                               
比如:                                            
                       
  AssignFile(Output, 'debug.log');                
  Rewrite(Output);                                
  ...                                             
  Writeln(blahblah);                              

    本站是提供個人知識管理的網絡存儲空間,所有內容均由用戶發(fā)布,不代表本站觀點。請注意甄別內容中的聯系方式、誘導購買等信息,謹防詐騙。如發(fā)現有害或侵權內容,請點擊一鍵舉報。
    轉藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多