在C ++中部分截断流(fstream或ofstream) [英] Partially truncating a stream (fstream or ofstream) in C++
问题描述
我试图使用fstream部分截断(或缩短)现有文件。我已经尝试写一个EOF字符,但这似乎什么也不做。
I am trying to partially truncate (or shorten) an existing file, using fstream. I have tried writing an EOF character, but this seems to do nothing.
任何帮助将被赞赏...
Any help would be appreciated...
推荐答案
我不认为你可以。有许多函数用于向上和向下移动 HANDLE < - > int < - > FILE *
的包装层次结构,至少在Windows上,但没有适当从iostreams对象中提取 FILE *
(如果确实是用一个实现的话)。
I don't think you can. There are many functions for moving "up and down" the wrapper hierarchy for HANDLE<->int<->FILE *
, at least on Windows, but there is no "proper" to extract the FILE *
from an iostreams object (if indeed it is even implemented with one).
您可能会发现此问题是您的帮助。
You may find this question to be of assistance.
我个人强烈建议你避开iostreams,他们设计不好,C ++很重,看起来很讨厌。查看 Boost的iostreams ,或换行 stdio.h (如果您需要使用课程)。
Personally I would strongly recommend steering clear of iostreams, they're poorly designed, heavily C++, and nasty to look at. Take a look at Boost's iostreams, or wrap stdio.h if you need to use classes.
stdio的相关功能是 ftruncate()。
The relevant function for stdio is ftruncate().
这篇关于在C ++中部分截断流(fstream或ofstream)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!