|
-
February 19th, 2009, 07:00 AM
#1
Dev-C++ error?
Hi!
I noticed a very strange behaviour of Dev-C++ compiler. I have a function which transforms a binary file (containing positive and negative integers as records) by moving all the integers one position (4 bytes) to the left (so the first record in the file is left `empty`). I have written a function like this:
Code:
void moveRecords(fstream & f) {
f.seekg(0,ios::beg);
int x=0,y=0;
f.read((char *)&x,sizeof(int));
if (f) {
f.read((char *)&y,sizeof(int));
while (f) {
f.seekp(-4,ios::cur);
f.write((char *)&x,sizeof(int));
x=y;
f.tellp();
f.read((char *)&y,sizeof(int));
}
}
f.clear();
f.seekp(0,ios::end);
f.write((char *)&x,sizeof(int));
f.clear();
}
It works fine! Now, if I delete or comment the line `f.tellp();`, nothing works fine anymore - just some first integers are moved and after that a while loop is finished (so I guess some error occurs). And the funny part is that it happens only in Dev-C++ compiler - if compiled with Borland, I don't have to write this useless line of `tellp`.. Why is that and how to get rid of it? Because in the situation, I must use the Dev-C++.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|