使用Win32 API处理文件与fstream [英] using win32 api for handling files vs. fstream

查看:203
本文介绍了使用Win32 API处理文件与fstream的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能解释每种方法的优点/缺点?
我什么时候要使用每个? (假设我当然在Windows上工作)

can anyone explain the advantages\disadvanteges of each method?
when would i want to use each? (assuming i''m working on windows of course)

推荐答案

fstream是C ++对象.它可以在任何操作系统上运行.
Win32 API仅在Windows中有效.

Windows中的fstream实现最终将调用Win32 API.

因此第一种方法将为您带来可移植性.
第二种方法执行起来会稍快一些.
fstream is a C++ object. It will work in any OS.
Win32 APIs will work only in Windows.

fstream implementation in Windows will eventually call the Win32 APIs.

So the first approach will give you portability.
The second approach will execute slightly faster.


它们有两种不同的理念,并且有一定的重叠区域.

当数据流定向到文件时,fstream实现C ++流的"概念".
通过与许多其他类(例如strembuff locale s)配合使用,它们的默认值几乎不起作用,但是您可以用模块化方式进行替换.

Win32 API是操作系统驱动的铁"表面.
它们提供了自己的许多功能",许多功能在内部由fstream 实现使用,一些几乎透明地(除了一些名称更改)在C ++级别公开,其他一些则未使用. />
还请考虑,许多API甚至与"windows"都不相关,而与文件系统"相关,并且在某些文件系统上相对于其他API的功能可能有限(例如,FAT的属性少于NTFS)

因此,如果您必须管理与文件系统相关的属性,那么本地API可能更适合(C ++模型对此不感兴趣),如果您必须控制数据的写入/读取方式,则fstream 可能更合适. />
还请考虑-即使fstreams 可以是二进制的-它们自然是面向文本的转换器,而本机API是面向二进制的批量移动器.
They have two different philosophy with a certain area of overlap.

fstream implements the "concept" of C++ stream when the data flow are directed to files.
It does so by cooperating with a number of other classes like strembuff and locales, whose defaults do almost nothing, but you can replace in modular way.

Win32 API are the surface of the "iron" that the operating system drives.
They provide their own a number of "features", many of them are used internally by the fstream implementation, some are almost transparently (apart some name changes) re-exposed at the C++ level, some other are left unused.

Consider also that many of the API are not even "windows" but "file system" related and can have limited functionality on certain file system respect to other (FAT has less attributes than NTFS, for example)

So, if you have to manage file system related attributes probably the native API are more suitable (C++ models are not interested in that), if you have to control the way data are written/read fstream is probably much suitable.

Consider also that -even if fstreams can be binary- they are naturally text oriented converters, while native API are binary oriented bulk movers.


非常感谢,因此没有Windows开发时差异很大.
或使用任何方法是否有限制?例如其中一个可用但另一个不可用的安全选项,或文件大小的限制?使用一种方法很容易实现这些操作,而用另一种方法很难实现这些操作吗?在Windows上使用Win32 API进行开发的最佳实践是什么?
thanks a lot, so there isn''t much diffrence when developing for windows.
or are there any limitations using any method? such as security options available on one but not on the other, or limitations on file size? are ther opertions that are very easy to implement using one way, but are much more difficult in the other? is the best practice for developing on windows to use the win32 api?


这篇关于使用Win32 API处理文件与fstream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆