2012-11-29 47 views
1

C++ ostream :: tellp的StreamWriter是否存在C#等價物?我正在將一些舊的C++代碼移植到C#中,但客戶端仍然希望繼續使用軟盤(讀取:舊設備),所以我需要找到一種方法來查找文件指針位置或查找我寫入的內容磁盤已經。C#相當於C++ ostream :: tellp在磁盤上的大小限制

下面是我創建至今的方法:我認爲你正在尋找

swOutput.BaseStream.Position 

private bool isDisketteBoundary(ref StreamWriter swOutput, int nCurrentDisketteNo) { 
     // Get current file pointer position 
     // long filePosition = nOStream.tellp(); <-- C++ code 
     long filePosition = 0; // <-- needs to change to find file pointer position 

     // Valid? 
     if(filePosition != -1) { 
      // Is the new size over a boundary? 
      float numDiskettes = (float)((float)filePosition/(float)Constants.DisketteSize); 
      int disketteCount = Convert.ToInt32(Math.Ceiling(numDiskettes)); 

      // Is the diskette count larger than the current index? 
      return (nCurrentDisketteNo < disketteCount) ? true : false; 
     } 
     else { 
      throw new Exception("Unable to get file pointer from StreamWriter"); 
     } 
} 
+0

然後升級你的客戶端! ;-) – Kos

+0

@Kos在他們向我公司支付的金額上,我認爲這可能是一個壞主意。 :P –

+0

真實姓名是「軟盤」=) – Calvin1602

回答