1

C++ ostream::tellp 的 StreamWriter 是否有 C# 等价物?我正在将一些旧的 C++ 代码移植到 C#,但客户端仍然想继续使用软盘(阅读:旧设备),所以我需要找到一种方法来找到文件指针位置或找到我写了多少磁盘已经。

以下是我到目前为止创建的方法:

 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");
      }
 }
4

1 回答 1

2

我想你正在寻找

swOutput.BaseStream.Position

请参阅 MSDN:http: //msdn.microsoft.com/en-us/library/system.io.stream.position.aspx

于 2012-11-29T14:53:42.963 回答