By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,389 Members | 1,847 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,389 IT Pros & Developers. It's quick & easy.

C/C++ language Standard I/O has problem in Redhat 7.2?

P: n/a
Dear all,

I write a simple program to test file open,read,close.
It worked fine in windows and unix, even redhat 8.0. And the compilers are
The problem is when using fread(or C++ istream::read() ) to read larger
than about 20,000 file position.
Then it'll cost moemry unlimitedly.
Does anyone know why? Thanks your help.
Here is my C code. Almost the same as C++ istream::read().
#include <cstdio>
#include <iostream>
using namespace std;

#define BYTES_PER_LOAD 4096

int main()

FILE *l_pFile=fopen("/mnt/windows/gds/demo.gds","rb");
if (l_pFile==NULL)
cout << "File open failure." << endl;
return 0;
unsigned char l_ucharBuf[BYTES_PER_LOAD];
fread(l_ucharBuf,sizeof(unsigned char),BYTES_PER_LOAD,l_pFile);
if (!feof(l_pFile)) { // file size > BYTES_PER_LOAD= 4096 Bytes
do {
fread(l_ucharBuf,sizeof(unsigned char),BYTES_PER_LOAD,l_pFile);
cout << "Current file position : " << ftell(l_pFile) << endl;
}while (!feof(l_pFile));
else {
/*... */
return 0;

Jul 19 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.