Microsoft KB Archive/168440

= You may receive an "error C2593: 'operator <<' is ambiguous" error message when you try to pass an __int64 variable to the ostream operator << =

Article ID: 168440

Article Last Modified on 5/26/2005

-

APPLIES TO

 The Standard C++ Library, when used with:  Microsoft Visual C++ 5.0 Enterprise Edition

 Microsoft Visual C++ 6.0 Enterprise Edition

 Microsoft Visual C++ 5.0 Professional Edition

 Microsoft Visual C++ 6.0 Professional Edition</li></ul>

 Microsoft Visual C++ 6.0 Standard Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q168440

<div class="symptoms_section">

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

error C2593: 'operator <<' is ambiguous

<div class="cause_section">

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

<div class="resolution_section">

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.

<div class="status_section">

STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.

This problem was corrected in Microsoft Visual C++ .NET.

<div class="moreinformation_section">

MORE INFORMATION
The following sample program demonstrates the problem and workaround: //Sample.cpp // Compiler Options : /GX

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

using namespace std;
 * 1) include

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


 * 1) endif

int main{ __int64 i64;

cout << i64 ;

return 0; }

Keywords: kberrmsg kbbug kbfix kbcrt kbnoupdate KB168440

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.