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

Article translations Article translations
Article ID: 168440
Expand all | Collapse all

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 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.

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;
}
				

Properties

Article ID: 168440 - Last Review: June 22, 2014 - Revision: 5.0
Keywords: 
kbbug kbcrt kberrmsg kbfix kbnoupdate KB168440

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com