Microsoft KB Archive/246934: Difference between revisions
(importing KB archive) |
m (Text replacement - """ to """) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 63: | Line 63: | ||
Here is a code sample that illustrates the problem and provides a workaround:<br /> | Here is a code sample that illustrates the problem and provides a workaround:<br /> | ||
<pre class="codesample">#include | <pre class="codesample">#include <iostream> | ||
#include | #include <fstream> | ||
using namespace std; | using namespace std; | ||
Line 70: | Line 70: | ||
int main() | int main() | ||
{ | { | ||
ifstream file( | ifstream file("c:\\config.sys",ios::in|ios::binary); | ||
static char buffer[10]; | static char buffer[10]; | ||
Line 76: | Line 76: | ||
if ( !file ) | if ( !file ) | ||
cout | cout << "unable to open file" << endl; | ||
else | else | ||
{ | { | ||
file.readsome(buffer,10); // It does not work properly. | file.readsome(buffer,10); // It does not work properly. | ||
//file.read( buffer, 10 ); // Uncomment this line for work around. | //file.read( buffer, 10 ); // Uncomment this line for work around. | ||
cout | cout << buffer << endl; | ||
cout | cout << endl << "File contents are:" << endl; | ||
file.seekg( 0 ); // Rewind file. | file.seekg( 0 ); // Rewind file. | ||
while( file.good() ) | while( file.good() ) | ||
{ | { | ||
file.getline( buffer, 10 ); | file.getline( buffer, 10 ); | ||
cout | cout << buffer << endl; | ||
} | } | ||
} | } |
Latest revision as of 13:50, 21 July 2020
Article ID: 246934
Article Last Modified on 7/30/2001
This article was previously published under Q246934
SYMPTOMS
The istream::readsome function does not read correct data from a file.
CAUSE
The basic_istream::readsome function has some limitations when used on certain streams. Moreover, the MSDN documentation for basic_istream::readsome states that internally basic_istream::readsome calls the read function. However, in the basic_istream::readsome implementation, the read function is never called.
RESOLUTION
Give preference to basic_istream::read.
STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.
MORE INFORMATION
Here is a code sample that illustrates the problem and provides a workaround:
#include <iostream> #include <fstream> using namespace std; int main() { ifstream file("c:\\config.sys",ios::in|ios::binary); static char buffer[10]; buffer[10] = 0; if ( !file ) cout << "unable to open file" << endl; else { file.readsome(buffer,10); // It does not work properly. //file.read( buffer, 10 ); // Uncomment this line for work around. cout << buffer << endl; cout << endl << "File contents are:" << endl; file.seekg( 0 ); // Rewind file. while( file.good() ) { file.getline( buffer, 10 ); cout << buffer << endl; } } return 0; }
Additional query words: stl
Keywords: kbbug KB246934