Microsoft KB Archive/102158: Difference between revisions

From BetaArchive Wiki
(importing KB archive)
 
m (Text replacement - ">" to ">")
 
(2 intermediate revisions by the same user not shown)
Line 70: Line 70:
== MORE INFORMATION ==
== MORE INFORMATION ==


The following code example demonstrates this problem by filling a buffer with the character sequence "01234567890..." and using an ifstream object to copy the data to another buffer. The transferred sequence reads as "013456..." Only the character "2" is missing from the sequence. The remainder of the sequence transfers correctly.
The following code example demonstrates this problem by filling a buffer with the character sequence "01234567890..." and using an ifstream object to copy the data to another buffer. The transferred sequence reads as "013456..." Only the character "2" is missing from the sequence. The remainder of the sequence transfers correctly.
=== Sample Code ===
=== Sample Code ===


Line 77: Line 77:
  */  
  */  


#include <iostream.h>
#include <iostream.h>
#include &lt;fstream.h&gt;
#include <fstream.h>


// To resolve the problem using Visual C++ 5.0, use the
// To resolve the problem using Visual C++ 5.0, use the
// following three statements instead of the preceding two:
// following three statements instead of the preceding two:
//  
//  
// #include &lt;iostream&gt;
// #include <iostream>
// #include &lt;fstream&gt;
// #include <fstream>
// using namespace std;
// using namespace std;


Line 90: Line 90:
void main(void)
void main(void)
{
{
   ofstream os(&quot;test.tmp&quot;);
   ofstream os("test.tmp");
   for (int i = 0; i &lt; 512; i++)
   for (int i = 0; i < 512; i++)
   {
   {
       os.put((char)('0' + i % 10));
       os.put((char)('0' + i % 10));
Line 99: Line 99:


   streampos pos;
   streampos pos;
   ifstream is(&quot;test.tmp&quot;);
   ifstream is("test.tmp");
// To resolve this error using Visual C++ 4.x and earlier, use the
// To resolve this error using Visual C++ 4.x and earlier, use the
// following line to open the ifstream instead of the line above.
// following line to open the ifstream instead of the line above.
// ifstream is(&quot;test.tmp&quot;, ios::binary);
// ifstream is("test.tmp", ios::binary);
   for (int k = 0; k &lt; 10; k++)
   for (int k = 0; k < 10; k++)
   {
   {
       pos = is.tellg();
       pos = is.tellg();
       cout &lt;&lt; (char)is.get();
       cout << (char)is.get();
   }
   }
}
}

Latest revision as of 10:07, 20 July 2020

Knowledge Base


Article ID: 102158

Article Last Modified on 7/5/2005



APPLIES TO

  • Microsoft Visual C++ 1.0 Professional Edition
  • Microsoft Visual C++ 1.5 Professional Edition
  • Microsoft Visual C++ 1.0 Professional Edition
  • Microsoft Visual C++ 2.0 Professional Edition
  • Microsoft Visual C++ 4.0 Standard Edition
  • Microsoft Visual C++ 4.1 Subscription
  • Microsoft Visual C++ 4.2 Enterprise Edition
  • Microsoft Visual C++ 4.2 Professional Edition



This article was previously published under Q102158


SYMPTOMS

When an application reads characters into an ifstream object opened in text mode, data may be lost and not placed into the buffer. The code does not provide any warning or other indication of this data loss.

STATUS

Microsoft has confirmed this to be a problem in the products listed at the beginning of this article. This problem was fixed in Visual C++ 5.0.

MORE INFORMATION

The following code example demonstrates this problem by filling a buffer with the character sequence "01234567890..." and using an ifstream object to copy the data to another buffer. The transferred sequence reads as "013456..." Only the character "2" is missing from the sequence. The remainder of the sequence transfers correctly.

Sample Code

/*
 * Compiler options needed:  -GX for 5.0 only
 */ 

#include <iostream.h>
#include <fstream.h>

// To resolve the problem using Visual C++ 5.0, use the
// following three statements instead of the preceding two:
// 
// #include <iostream>
// #include <fstream>
// using namespace std;


void main(void)
{
   ofstream os("test.tmp");
   for (int i = 0; i < 512; i++)
   {
      os.put((char)('0' + i % 10));
   }
   os.put('\n');
   os.close();

   streampos pos;
   ifstream is("test.tmp");
// To resolve this error using Visual C++ 4.x and earlier, use the
// following line to open the ifstream instead of the line above.
// ifstream is("test.tmp", ios::binary);
   for (int k = 0; k < 10; k++)
   {
      pos = is.tellg();
      cout << (char)is.get();
   }
}
                


Additional query words: kbVC400bug 8.00 8.00c 9.00

Keywords: kbbug kbfix kbvc500fix kbcpponly kbcode kbcompiler KB102158