标准C ++文件大小??? [英] Standard C++ file size???

查看:81
本文介绍了标准C ++文件大小???的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有标准的C ++方法来确定

文件的大小?

Is there any standard C++ way to determine the size of a
file before it is read?

推荐答案

Peter Olcott写道:
Peter Olcott wrote:

在读取之前是否有任何标准的C ++方法来确定

文件的大小?
Is there any standard C++ way to determine the size of a
file before it is read?



No.标准C ++方式是打开文件进行阅读,寻找文件结尾的

并获得该职位。如果你需要磁盘上的文件大小

(并且你有文件名)没有触摸以任何

方式,使用现有平台(OS)机制获取文件统计数据

(统计数据)。 RTFM对您的操作系统进行编程。


V

-

请在回复e时删除资金'A' -mail

我没有回复最热门的回复,请不要问

No. The "standard C++ way" is to open the file for reading, seek to the
end of the file and get the position. If you need the size of the file
on disk (and you have the name of the file) without "touching" is in any
way, use the existing platform (OS) mechanisms to get the "file stats"
(statistics). RTFM on programming your OS.

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


On Sun,2008年10月5日10:46 :43 -0500,Peter Olcott写道:
On Sun, 05 Oct 2008 10:46:43 -0500, Peter Olcott wrote:

是否有任何标准的C ++方法来确定文件大小之前

被读取?
Is there any standard C++ way to determine the size of a file before it
is read?



我想最简单的方法是使用二进制操作模式并尝试

获得该模式下的大小。


一些二进制文件操作在
http://www.cplusplus.com/doc/tutorial/files.html


有一些例子,我想它们可以让你开始;)

I guess the easiest would be to use the binary operation mode and try to
get the size in that mode.

Some binary file operations are treated in
http://www.cplusplus.com/doc/tutorial/files.html

with some examples, they can get you started, I suppose ;)


Victor Bazarov写道:
Victor Bazarov wrote:

Peter Olcott写道:
Peter Olcott wrote:

>在读取文件之前,是否有任何标准的C ++方法来确定文件的大小?
>Is there any standard C++ way to determine the size of a file before
it is read?



No.标准C ++方式是打开文件进行阅读,寻找文件结尾的

并获得该职位。如果你需要磁盘上的文件大小

(并且你有文件名)没有触摸以任何

方式,使用现有平台(OS)机制获取文件统计数据

(统计数据)。 RTFM对您的操作系统进行编程。


No. The "standard C++ way" is to open the file for reading, seek to the
end of the file and get the position. If you need the size of the file
on disk (and you have the name of the file) without "touching" is in any
way, use the existing platform (OS) mechanisms to get the "file stats"
(statistics). RTFM on programming your OS.



请注意文件大小是一个不那么琐碎的概念,而不是天真地出现:b $ b出现:它是在磁盘上分配的字节数吗?您可以在文本模式下从文件中读取的

字符数?您可以在二进制模式下读取的字节数

?那么符号链接呢?


正如Victor所说,你的平台很可能会暴露出一个合适的函数

产生的数字对应于一个特定的

" size"对于它可以应用的元素。 POSIX系统必须具有

stat - 注意这个模数平台特定扩展,不知道

什么是大小。适用于某些文件类型 - ; Win32具有GetFileAttributesEx和

GetFileAttributes等。大文件支持的变体。 (例如stat64)

也很常见。


当然,Boost.Filesystem可能会提供你需要的东西

盒。


-

Gennaro Prota | name.surname yahoo.com

Breeze C ++(预览版):< https://sourceforge.net/projects/breeze/>

你需要C ++方面的专业知识吗? ?我有空。

Note that "file size" is a less trivial notion than it might naively
appear: is it the number of bytes allocated on disk? The number of
characters you can read from the file in text mode? The number of bytes
you can read in binary mode? And what about symbolic links?

As Victor said, your platform is likely to expose a suitable function
yielding the number which corresponds to one particular definition of
"size" for the elements it can be applied to. POSIX systems must have
stat --note that this, modulo platform-specific extensions, doesn''t know
what "size" is for some file types--; Win32 has GetFileAttributesEx and
GetFileAttributes, etc. Variants for "large file support" (e.g. stat64)
are also common.

Of course, Boost.Filesystem may provide what you need just out of the
box.

--
Gennaro Prota | name.surname yahoo.com
Breeze C++ (preview): <https://sourceforge.net/projects/breeze/>
Do you need expertise in C++? I''m available.


这篇关于标准C ++文件大小???的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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