Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

print __int64 via ostream cout

29 views
Skip to first unread message

Andre Folkers

unread,
Aug 24, 1998, 3:00:00 AM8/24/98
to
Hi !

I don't get an __int64 value print on standard output with the cout
stream!

I tried the following:

#include <iostream>
using namespace std;
void main()
{
__int64 intvalue=0xffffffffffffffff;
cout << intvalue << endl;
return;
}

And I got the following error-message from msvc5.0:

R:\stl-test\msvcstl.cpp(38) : error C2593: 'operator <<' is ambiguous

Does anyone know, if there is a solution with ostreams. I already know
the printf-solution with %I64 option!

Thanks in advance!

Andre Folkers

Jonathan Dodds

unread,
Aug 24, 1998, 3:00:00 AM8/24/98
to
As the underscores in the name should tell you, __int64 is a non-standard
type. Unlike the other __int* types __int64 is not a synonym for a standard
type.

You will probably need to write your own stream inserter for __int64 using
sprintf.

Andre Folkers wrote in message
<35E17C3C...@informatik.mu-luebeck.de>...

Andrew Tucker

unread,
Aug 24, 1998, 3:00:00 AM8/24/98
to

Here's the implementation I use:


/*
This function is necessary to overcome the fact that an
ostream operator<< is not supplied for the built in type
__int64.
*/
template <class _E, class _Tr>
inline basic_ostream<_E, _Tr>& __cdecl operator<<( basic_ostream<_E, _Tr>& _O, __int64 i64Val)
{
wchar_t wchBuf[32];

// VC5BUG: _i64tow cannot handle negative numbers
if (i64Val < 0)
{
_O << _U("-");
i64Val *= -1;
}

return (_O << _i64tow(i64Val, wchBuf, 10)) ;
}


Jonathan Dodds (do...@amsa.com) wrote:
: As the underscores in the name should tell you, __int64 is a non-standard

: >
: >
:
:

--
--
/* Andrew */
WWW: http://www.halcyon.com/ast
Email: a...@halcyon.com


Andrew T. Brown

unread,
Aug 24, 1998, 3:00:00 AM8/24/98
to

This was discussed as a "Bug of the Month" in Windows Developer's Journal a
few months back. It provided a code snippet to provide __int64 support.

(Aside: I could quibble with labeling this issue a "bug"... I don't see why
one should assume that standard library support will be extended to
non-standard types; but certainly users will notice it...)

// -----------------------------------------------------------------------
// andrew todd brown
// mailto:andre...@acm.org
// -----------------------------------------------------------------------

0 new messages