文件读取 - C++文件流读写文件,文件大小是否有限制?
高洛峰
高洛峰 2017-04-17 14:48:30
0
1
579

一年前只会C语言的时候,曾用C写过一个基于Huffman树的文件压缩程序。打开文件的用的是C标准库中的fopen()。后来发现这样的程序对于稍微大一点的程序(1M以上大概)就无法运行了。在搜索引擎上找了半天特不知道问题出在哪。

今年用C++重新写这个程序,打算使用文件流打开文件,但不知道对于比较大的文件是都可以正常运行。

我的疑问如下:

  1. C与C++读取文件的方式有区别吗?

  2. 如果确实不能“一口气”打开大文件,什么是正确的打开方式?

  3. C/C++里打开文件的底层操作是什么呢?

贪心地问了三个问题,大神们答哪个都可以哈。

先在此谢过大家了!

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(1)
PHPzhong

I don’t know what the questioner’s code for reading and writing files looks like, and I suspect there is something wrong with it.
If there is a problem if it is above 1M, it is unlikely to be due to relevant restrictions. It should be a code problem.

Answer a few questions first.
1. It can be said that there is. C++ can use C's file operation functions, but C cannot use C++'s fstream. This is for the standard library, not an operating system specific API.
2. I don’t know how big the file that the question is about to open is. If you really need it, consider using the system API.
3. The underlying operation is actually an encapsulation of system calls.

My talent is limited, so please forgive me if there are any mistakes.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!