Microsoft KB Archive/168440: Difference between revisions

From BetaArchive Wiki
(importing KB archive)
 
m (Text replacement - "&" to "&")
 
(3 intermediate revisions by the same user not shown)
Line 12: Line 12:
<div id="TitleRow">
<div id="TitleRow">


= <span id="KB168440"></span>You may receive an &quot;error C2593: 'operator &lt;&lt;' is ambiguous&quot; error message when you try to pass an __int64 variable to the ostream operator &lt;&lt; =
= <span id="KB168440"></span>You may receive an "error C2593: 'operator <<' is ambiguous" error message when you try to pass an __int64 variable to the ostream operator << =




Line 60: Line 60:
== SYMPTOMS ==
== SYMPTOMS ==


If you try to pass an __int64 variable to the ostream operator &lt;&lt;, you get the following error:
If you try to pass an __int64 variable to the ostream operator <<, you get the following error:
<div class="errormessage">
<div class="errormessage">


error C2593: 'operator &lt;&lt;' is ambiguous
error C2593: 'operator <<' is ambiguous


</div>
</div>
Line 72: Line 72:
== CAUSE ==
== CAUSE ==


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


</div>
</div>
Line 79: Line 79:
== RESOLUTION ==
== RESOLUTION ==


Define your own version of operator &lt;&lt;. The following sample code section shows a simple solution for &lt;&lt; operator that converts the __int64 variable to a char * type and passes it to the ostream &lt;&lt; operator.
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>
</div>
Line 86: Line 86:
== STATUS ==
== STATUS ==


Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the &quot;Applies to&quot; section.<br />
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.<br />
<br />
<br />
This problem was corrected in Microsoft Visual C++ .NET.
This problem was corrected in Microsoft Visual C++ .NET.
Line 101: Line 101:
//#define WORKAROUND  //Uncomment this line to workaround
//#define WORKAROUND  //Uncomment this line to workaround


#include&lt;iostream&gt;
#include<iostream>
using namespace std;
using namespace std;


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


cout &lt;&lt; i64 ;
cout << i64 ;


return 0;
return 0;

Latest revision as of 12:29, 21 July 2020

Knowledge Base


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
    • Microsoft Visual C++ 6.0 Standard Edition



This article was previously published under Q168440

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

Keywords: kberrmsg kbbug kbfix kbcrt kbnoupdate KB168440