一年前只会C语言的时候,曾用C写过一个基于Huffman树的文件压缩程序。打开文件的用的是C标准库中的fopen()
。后来发现这样的程序对于稍微大一点的程序(1M以上大概)就无法运行了。在搜索引擎上找了半天特不知道问题出在哪。
今年用C++重新写这个程序,打算使用文件流打开文件,但不知道对于比较大的文件是都可以正常运行。
我的疑问如下:
C与C++读取文件的方式有区别吗?
如果确实不能“一口气”打开大文件,什么是正确的打开方式?
C/C++里打开文件的底层操作是什么呢?
贪心地问了三个问题,大神们答哪个都可以哈。
先在此谢过大家了!
PHPz2017-04-17 14:50:30
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.