Link to home
Start Free TrialLog in
Avatar of berox
berox

asked on

C++ Language question

I have been since recently in C++-programming after
several years of turbo pascal. Now I've encountered a
problem that I just can't seem to solve.
I used in tp the function blockread to read several bytes
at once in a memory block assigned by memalloc.

the class I use in c++ is that of ifstream to open the
file.
reserve x number of 16-bytes paragraphs with memalloc.

The thing I want to do is read n bytes in one time out of
the file opened by ifstream and place them in the buffer
assigned by memalloc.

someone knows how to solve this problem ?

Avatar of AVaulin
AVaulin
Flag of Ukraine image

Use FILE structure and fopen, fread and fclose functions instead ifstream class. This way is the easiest.
Avatar of berox
berox

ASKER

still remains the question how can I put them in a buffer allocated by memalloc and (I forgot to put it in my former question)is there a function to read the memory locations reserved by memalloc (something like Mem[Seg:ofs] in TP), or is it just "pointer-work"
Example:

struct YourStuct
{
 int int1;
 floaf float1;
 char str[20];
}

void YourFunction( void )
{
 YourStuct* s;
 FILE* fp;

 s = new YourStuct [20];
 fp = fopen( "yourfile", "rb" );
 fread( s, sizeof(YourStuct), 20, fp );
 fclose( fp );

// do wht you want with s

 delete s;
}
ASKER CERTIFIED SOLUTION
Avatar of shappir
shappir

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial