我们可以在SDL2中使用std :: fstream代替SDL_RWops吗? [英] Can we use std::fstream instead of SDL_RWops in SDL2?
问题描述
作为标题,在处理I/O文件方面,SDL_RWops
是否比std::fstream
有任何优势?因为我更熟悉std::fstream
,我可以改用它吗?
As the title, does SDL_RWops
have any advantages over std::fstream
in dealing with I/O file? Can I use std::fstream
instead because I am more familiar with it?
推荐答案
通过阅读他们的文档,您会发现std::fstream
是一个:
By reading their documentation, you can find that std::fstream
is an:
用于对文件进行操作的输入/输出流类.
Input/output stream class to operate on files.
另一方面,SDL_RWops
还有更多内容:
On the other side, SDL_RWops
is something more:
SDL_RWops是基于I/O的抽象.它提供了用于读取,写入和查找流中数据的接口,而调用者无需知道数据来自何处.
SDL_RWops is an abstraction over I/O. It provides interfaces to read, write and seek data in a stream, without the caller needing to know where the data is coming from.
例如,RWops可能由内存缓冲区,磁盘上的文件或与Web服务器的连接提供,而对调用方使用数据的方式没有任何更改.
For example, a RWops might be fed by a memory buffer, or a file on disk, or a connection to a web server, without any changes to how the caller consumes the data.
相当强的抽象性.
那么,您可以为文件使用std::fstream
代替SDL_RWops
吗?绝对,如果您感到更有信心,那就去吧.后者是对游戏中任何类型的流的有用抽象,因此,优点是除了读取文件之外,还有其他优点.
So, can you use std::fstream
in place of SDL_RWops
for your files? Absolutely, if you feel more confident, go with it. The latter is an useful abstraction over any sort of stream in your game, so the advantage is something beyond reading a file.
这篇关于我们可以在SDL2中使用std :: fstream代替SDL_RWops吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!