Input to output using >> and <<

I'm a C++ beginner, currently studying stacks, with a basic knowledge of both C and C++. I am using Code::Blocks as my IDE with the MingW compiler that comes along. I have a question regarding the operators >> and <<.
What would happen if both the operands are streams?
say something like:

1
2
3
4
5
6
7
8
9
10
0	#include<iostream>
1
2	using namespace std;
3
4	int main()
5	{
6	    cout << cin;
7	    cin >> cout;
8		return 0;
9	}


The code of line 4 compiles fine, and executes too, giving me the answer:
[code]
F:\College>test
0x445468
F:\College>
[\code]

Whereas line 5 gives me an error stating ambigous overload for operator>>.

Further, I tried a simple variation: I changed 'cin' in line 4 to '&cin'. The resulting execution gave me a slightly different answer: 0x445460

Could anyone explain to me:
a) the significance of 0x445468?
b) why line 4 doesn't generate an error?
c) why line 5 does?
d) why changing cin to &cin decreased the output by 8?
a. It's a fortuitous memory address. Specifically, the location the object std::cin occupied during that particular run of the program.
b. There's an overload for operator<<() which takes an std::ostream and a pointer to a stream function (I can't remember the exact signature, but I think it has the same signature as std::endl).
c. I'd need to see the error to answer this question, but I can't be bothered to try it myself.
d. Actually, I don't know. I think it should give the same result.
a. Yet different runs of the program after rebuilding while occasionally changing cin to &cin still yield the same numbers.

b.
CodeBlocks says that the ambiguities are caused by matches to the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// istream classes -*- C++ -*-

...

  template<typename _CharT, typename _Traits>
    basic_istream<_CharT, _Traits>&
    basic_istream<_CharT, _Traits>::
    operator>>(__istream_type& (*__pf)(__istream_type&))
    { return __pf(*this); }

...

  template<typename _CharT, typename _Traits>
    basic_istream<_CharT, _Traits>&
    basic_istream<_CharT, _Traits>::
    operator>>(__ios_type& (*__pf)(__ios_type&))
    {
      __pf(*this);
      return *this;
    }

...

  template<typename _CharT, typename _Traits>
    basic_istream<_CharT, _Traits>&
    basic_istream<_CharT, _Traits>::
    operator>>(ios_base& (*__pf)(ios_base&))
    {
      __pf(*this);
      return *this;
    }

...

  template<typename _CharT, typename _Traits>
    basic_istream<_CharT, _Traits>&
    basic_istream<_CharT, _Traits>::
    operator>>(__streambuf_type* __sbout)
    {
      ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
      sentry __cerb(*this, false);
      if (__cerb && __sbout)
	{
	  try
	    {
	      if (!__copy_streambufs(this->rdbuf(), __sbout))
		__err |= ios_base::failbit;
	    }
	  catch(...)
	    { this->_M_setstate(ios_base::failbit); }
	}
      else if (!__sbout)
	__err |= ios_base::failbit;
      if (__err)
	this->setstate(__err);
      return *this;
    }


While I do understand templates a bit, this goes way over my head.
Thanks.

Topic archived. No new replies allowed.