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

C

cylin

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
g++,kylix,vc++6,bcb++6.
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 {
/*... */
}
fclose(l_pFile);
return 0;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top