Thread: cout << (_int64 object)

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267

    cout << (_int64 object)

    using VC++ 6.0 compiler, how to use cout to display an _int64 object. Is there a solution with that compiler?
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
       _int64 x;
       cout << x;
    
      return 0;
    }
    error message
    Code:
    error C2593: 'operator <<' is ambiguous

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Use a better compiler? Even then I don't know if that would suppport a _int64
    Last edited by prog-bman; 10-20-2005 at 02:16 PM.
    Woop?

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    It works for me on VC 6.0. You may need to install a service pack or get a fix from dinkumware or download a different version of the standard library (I think I'm using 3.08 which is not the one that ships with VC 6).

    BTW, I thought it was supposed to be __int64, although _int64 also works for me.

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    I do get that error if I use <iostream.h>, make sure you are using <iostream>.

  5. #5
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    I have SP5 installed. overloading the << operator works.
    Code:
    ostream& operator<<(ostream& out, _int64 n)
    {
    	printf("%I64d", n);
    	return out;
    }
    Last edited by Ancient Dragon; 10-20-2005 at 02:31 PM.

  6. #6
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Isn't it better to avoid mixing printf and cout?
    Code:
    ostream& operator<< (ostream &o, _int64 n)
    {
       char buffer [ sizeof n * CHAR_BIT + 1 ]; /* plenty of space */
       sprintf(buffer, "%I64d", n);
       return o << buffer;
    }
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  7. #7
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Quote Originally Posted by Dave_Sinkula
    Isn't it better to avoid mixing
    normally -- yes. sprintf() and printf() both use the same routines to parse the format specification string, so it doesn't really matter which one of those are used. and cout and printf() call the same low-level printing functions in some implementations, such as VC++ 6.0 where they both call with win32 api function WriteFile().


    I suppose some compilers/platforms may have some serious objects about mixing iostream library functions with standard C file functions, but I have never had any problems with any Microsoft compilers (yet!).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. cout << SunTradingLLC << "is looking for C++ Software Developers" << endl;
    By sun trading in forum Projects and Job Recruitment
    Replies: 1
    Last Post: 04-02-2008, 11:48 AM
  2. Replies: 4
    Last Post: 01-23-2008, 06:21 AM
  3. cout << string
    By siavoshkc in forum C++ Programming
    Replies: 10
    Last Post: 07-26-2007, 12:51 PM
  4. Finding object code
    By kidburla in forum C Programming
    Replies: 3
    Last Post: 11-29-2005, 01:09 PM