Bug in MS's fstream? 
Author Message
 Bug in MS's fstream?

Hi
I don't know if I just have it wrong or what it is
If you have any answer please reply to my email address too -

anyhow
I have a textfile that looks like this
0014;NILSSON;KERSTIN;;;;;;
0016;NYLANDER;MARGARETA;;;;;;
0016;SVENSSON;OVE;;;;;;
and so on

and I have a small program that open and read this file..
#include <fstream.h>

void main(void)
  {
 char buffer[1000];
 long counter = 0;
 long current_pos = 0;
 long total = 0;
 long pos = 0;

 ofstream fout("Wfkper.dat", ios::app | ios::trunc);
 ifstream finFtg;
 finFtg.open("Wfkper.txt", ios::nocreate);
 if (finFtg.good())
 {
  finFtg.seekg(0, ios::end);
  total = finFtg.tellg();
  finFtg.seekg(0);

 while (finFtg.getline(buffer,1000))
  {
      fout << buffer << endl;
   counter++;
   current_pos = finFtg.tellg();  //Bug??
   current_pos = (current_pos*100)/total;
   cout << "\trow: " << counter << "\t" <<
   current_pos << "%" << "\r" << flush;
  }
 }
 else
 cout << "Error opening file.\n";
 cout << endl;
 counter = 0;

Quote:
}

as you see the program doesn't do anything special
it opens the file look how big it is (tellg) and reads every line
increasing current_pos every time to
have a little counter for the user...
anyhow when I run the file I showed in the beginning the outcome looks
like this

0014;NILSSON;KERSTIN;;;;;;
0016;NYLANDER;MARGARETA;;;;;;
016;SVENSSON;OVE;;;;;;   <--- missing a zero

this only happens here and there, maybe every 50 to 100 row and if I
remove the  "current_pos = finFtg.tellg();" then I don't get this error.

I have tried to compile using MSVC 1.5, 4.2 and 5.0 with the same
problem, using Borland C++ 5.0 I didn't get this error.

Is this a bug or is it just me that have it wrong?
hopefully it's just I how have forgotten something
if you want I can send you a sample with this...

best regard
Niklas Olsson



Fri, 22 Dec 2000 03:00:00 GMT  
 Bug in MS's fstream?

Hi
I don't know if I just have it wrong or what it is
If you have any answer please reply to my email address too -

anyhow
I have a textfile that looks like this
0014;NILSSON;KERSTIN;;;;;;
0016;NYLANDER;MARGARETA;;;;;;
0016;SVENSSON;OVE;;;;;;
and so on

and I have a small program that open and read this file..
#include <fstream.h>

void main(void)
  {
 char buffer[1000];
 long counter = 0;
 long current_pos = 0;
 long total = 0;
 long pos = 0;

 ofstream fout("Wfkper.dat", ios::app | ios::trunc);
 ifstream finFtg;
 finFtg.open("Wfkper.txt", ios::nocreate);
 if (finFtg.good())
 {
  finFtg.seekg(0, ios::end);
  total = finFtg.tellg();
  finFtg.seekg(0);

 while (finFtg.getline(buffer,1000))
  {
      fout << buffer << endl;
   counter++;
   current_pos = finFtg.tellg();  //Bug??
   current_pos = (current_pos*100)/total;
   cout << "\trow: " << counter << "\t" <<
   current_pos << "%" << "\r" << flush;
  }
 }
 else
 cout << "Error opening file.\n";
 cout << endl;
 counter = 0;

Quote:
}

as you see the program doesn't do anything special
it opens the file look how big it is (tellg) and reads every line
increasing current_pos every time to
have a little counter for the user...
anyhow when I run the file I showed in the beginning the outcome looks
like this

0014;NILSSON;KERSTIN;;;;;;
0016;NYLANDER;MARGARETA;;;;;;
016;SVENSSON;OVE;;;;;;   <--- missing a zero

this only happens here and there, maybe every 50 to 100 row and if I
remove the  "current_pos = finFtg.tellg();" then I don't get this error.
I have tried to compile using MSVC 1.5, 4.2 and 5.0 with the same
problem, using Borland C++ 5.0 I didn't get this error.

Is this a bug or is it just me that have it wrong?
hopefully it's just I how have forgotten something
if you want I can send you a sample with this...

best regard
Niklas Olsson



Fri, 22 Dec 2000 03:00:00 GMT  
 Bug in MS's fstream?


Quote:
> I don't know if I just have it wrong or what it is
> this only happens here and there, maybe every 50 to 100 row and if I
> remove the  "current_pos = finFtg.tellg();" then I don't get this error.
> I have tried to compile using MSVC 1.5, 4.2 and 5.0 with the same
> problem, using Borland C++ 5.0 I didn't get this error.

> Is this a bug or is it just me that have it wrong?

More like a feature. Try opening all your files in binary mode. The
program will probably behave the way you want.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com



Sat, 23 Dec 2000 03:00:00 GMT  
 Bug in MS's fstream?
When in doubt it's a Microsoft bug.  I have personally encoutered over 30 bugs
with Visual C++ 5.0 where microsoft had left out code, had code commented out
in THEIR source files.  And the worst of all they forgot to finish their Slider
control!!!!!


Tue, 02 Jan 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. bug in fstream? (works with fstream.h)

2. Serious BUG in fstream

3. fstream bug?

4. Bug in iostream / fstream

5. Bug in fstream ?

6. Debugger bug now official MS bug

7. BUG / buffer overrun bug -- ATTN: MS and all

8. fstream ./. fstream.h

9. Can't spawn UI for MS Word or Any MS Office Application from asmx

10. fstream: I can't get it to work correctly

11. MS-DOS NRO (an 'NROFF'- 'RNO'-like Source in C)

12. Bugs in Turbo C's Patch for their First Bugs

 

 
Powered by phpBB® Forum Software