2012-11-29 37 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

回答