DOCUMENT:Q246934 30-JUL-2001 [visualc] TITLE :BUG: istream::readsome Does Not Read Correctly on File Stream PRODUCT :Microsoft C Compiler PROD/VER: OPER/SYS: KEYWORDS: ====================================================================== 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 this to be a bug in the Microsoft products listed at the beginning of this article. MORE INFORMATION ================ Here is a code sample that illustrates the problem and provides a workaround: #include #include 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 : Issue type : kbbug ============================================================================= THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY. Copyright Microsoft Corporation 2001.