BUG: Stream Operator << Cannot Handle __int64 Type

Last reviewed: October 8, 1997
Article ID: Q168440
The information in this article applies to:
  • The Standard C++ Library included with: - Microsoft Visual C++, 32-bit Editions, version 5.0

SYMPTOMS

If you try to pass an __int64 variable to the ostream operator <<, you get the following error:

   "error C2593: 'operator <<' is ambiguous"

CAUSE

There is no operator << for __int64 type defined for the ostream class.

RESOLUTION

Define your own version of operator <<. The following sample code section shows a simple solution for << operator that converts the __int64 variable to a char * type and passes it to the ostream << operator.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

The following sample program demonstrates the problem and workaround:

   //Sample.cpp
   // Compiler Options : /GX

   //#define WORKAROUND   //Uncomment this line to workaround

   #include<iostream>
   using namespace std;

   #ifdef WORKAROUND
   std::ostream& operator<<(std::ostream& os, __int64 i )
   {
       char buf[20];
       sprintf(buf,"%I64d", i );
       os << buf;
       return os;
   }

   #endif

   int main(){
   __int64  i64;

   cout << i64 ;

   return 0;
   }
Keywords          : CRTIss vcbuglist500 kberrmsg kbbuglist
Version           : 5.0
Platform          : NT WINDOWS
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.

Last reviewed: October 8, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.