embarcadero / borland TMemoryStream和TFileStream的标准C等价物是什么?

weixin_38107492 2019-09-12 10:43:58
我找到了遗留源代码,这里摘录 – TMemoryStream *DFile = new TMemoryStream; TFileStream*BFile = new TFileStream; 以下是上述类的一些官方记录数据: > TMemoryStream Wiki& TMemoryStream Doc with example> TFileStream Wiki& TFileStream Doc(Same thing) > TMemoryStream& TFileStream有同样的目的吗?>如果我们考虑二进制数据输出流一段时间,那么我们可以取代TMemoryStream& TFileStreamwith std :: ostream&std :: ofstream分别?>(我有点困惑)何时使用编译器特定的TMemoryStream& TFileStreamover std :: ostream& std :: ofstream分别? >如果我们进行上述事情,我们可以获得哪些优势?
...全文
18 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_38141078 2019-09-12
  • 打赏
  • 举报
回复
Is TMemoryStream & TFileStream has same purpose ? 它们具有类似的界面,但它们有不同的用途. TMemoryStream从/向内存块读取/写入数据. TFileStream代替从/向文件读/写数据. If we consider binary data output streaming for awhile then can we replace TMemoryStream & TFileStream with std::ostream & std::ofstream respectively? TFileStream写入文件. std :: ofstream写入文件.所以,你可以用std :: ofstream替换TFileStream,是的. TMemoryStream有点棘手. TMemoryStream写入根据需要动态(重新)分配的内存块.没有用于写入动态内存块的标准C流.除非你考虑std :: ostringstream,它用于输出字符串,而不是二进制数据.或std :: vector< char>,它是动态的,但没有流接口. 但是,std :: ostream可以使用你想要的任何std :: streambuf,并且有很多第三方自定义std :: streambuf实现可用于从/向(动态)内存读/写.例如,this one写入std :: array< char,N>,但您可以调整它以写入std :: vector< char>代替.或者找到另一种适合您需求的实现.或者自己写. When to use compiler specific TMemoryStream & TFileStream over std::ostream & std::ofstream respectively? 当您需要直接与Borland / Embarcadero的RTL / VCL / FMX框架连接时,请使用TMemoryStream / TFileStream.否则你应该使用标准的C类.

435

社区成员

发帖
与我相关
我的任务
社区描述
其他技术讨论专区
其他 技术论坛(原bbs)
社区管理员
  • 其他技术讨论专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧