Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


Symptoms

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

↑ Back to the top


Cause

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

↑ Back to the top


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.

↑ Back to the top


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.

↑ Back to the top


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

↑ Back to the top


Keywords: kbvc600applies, kbvc600wrapup, kbbug, kbcrt, kbdsupport, kberrmsg, kbfix, kbnoupdate, kbbillprodsweep, kb

↑ Back to the top

Article Info
Article ID : 168440
Revision : 1
Created on : 1/7/2017
Published on : 6/22/2014
Exists online : False
Views : 182