其他分享
首页 > 其他分享> > embarcadero / borland TMemoryStream和TFileStream的标准C等价物是什么?

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

作者:互联网

我找到了遗留源代码,这里摘录 –

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分别?

>如果我们进行上述事情,我们可以获得哪些优势?

解决方法:

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类.

标签:ostream,ofstream,c,cbuilder
来源: https://codeday.me/bug/20190828/1748198.html