B
Birt
1.
In a program, there will be several files needed to be accessed. Is it
necessary to design a class that handles reading/writing files?
2.
For a struct data type,
struct mystruct
{
int int1;
char b;
int int2;
}
How to using >> and << for writing and reading objects of struct Date?
3.
Needs to read from 1000 ints from a binary file of integers.
Code 1:
ifstream instream;
int B[1000];
unsigned k = 0;
while(instream.eof() && m<1000){
instream >> B[k];
++k;
}
Code 2:
void read4bytes(void *p)
{
instream.read((char*)p, 4);
}
unsigned k = 0;
int* ptr;
while(k<1000)
{
read4bytes(ptr);
B[k] = *ptr;
++k;
}
Is Code 1 higher level of reading files compared to Code 2?
Is Code 1 faster compared to Code 2?
Should always use coding like Code 1 for reading files?
Thanks for your help!
In a program, there will be several files needed to be accessed. Is it
necessary to design a class that handles reading/writing files?
2.
For a struct data type,
struct mystruct
{
int int1;
char b;
int int2;
}
How to using >> and << for writing and reading objects of struct Date?
3.
Needs to read from 1000 ints from a binary file of integers.
Code 1:
ifstream instream;
int B[1000];
unsigned k = 0;
while(instream.eof() && m<1000){
instream >> B[k];
++k;
}
Code 2:
void read4bytes(void *p)
{
instream.read((char*)p, 4);
}
unsigned k = 0;
int* ptr;
while(k<1000)
{
read4bytes(ptr);
B[k] = *ptr;
++k;
}
Is Code 1 higher level of reading files compared to Code 2?
Is Code 1 faster compared to Code 2?
Should always use coding like Code 1 for reading files?
Thanks for your help!