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");
}
}
答案 0 :(得分:2)
我认为你在寻找
swOutput.BaseStream.Position
请参阅MSDN:http://msdn.microsoft.com/en-us/library/system.io.stream.position.aspx。