Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

why does visual studio 2005 do this? 2

Status
Not open for further replies.

jjjkkk77

Programmer
Jun 14, 2007
10
US
hi guys,

I tried to compile a program like this

#include <iostream>
using namespace std;

int main()
{
float f, g = 0;
cin << f; //wrong here, should be >>
return 0;
}


So I just deliberately inverted the direction of io stream direction. Then visual studio 2005 compiled this with 41 errors? Why so many errors with many repeated ones?

Error 1 error C2784: 'std::basic_ostream<char,_Traits> &std::eek:perator <<(std::basic_ostream<char,_Traits> &,unsigned char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream' c:\acm\zju\1048\financialmanagement.cpp 7
Error 2 error C2784: 'std::basic_ostream<char,_Traits> &std::eek:perator <<(std::basic_ostream<char,_Traits> &,unsigned char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream' c:\acm\zju\1048\financialmanagement.cpp 7
Error 3 error C2784: 'std::basic_ostream<char,_Traits> &std::eek:perator <<(std::basic_ostream<char,_Traits> &,unsigned char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream' c:\acm\zju\1048\financialmanagement.cpp 7
Error 4 error C2784: 'std::basic_ostream<char,_Traits> &std::eek:perator <<(std::basic_ostream<char,_Traits> &,unsigned char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream' c:\acm\zju\1048\financialmanagement.cpp 7
Error 5 error C2784: 'std::basic_ostream<char,_Traits> &std::eek:perator <<(std::basic_ostream<char,_Traits> &,const unsigned char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream' c:\acm\zju\1048\financialmanagement.cpp 7
Error 6 error C2784: 'std::basic_ostream<char,_Traits> &std::eek:perator <<(std::basic_ostream<char,_Traits> &,const unsigned char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream' c:\acm\zju\1048\financialmanagement.cpp 7
Error 7 error C2784: 'std::basic_ostream<char,_Traits> &std::eek:perator <<(std::basic_ostream<char,_Traits> &,const unsigned char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream' c:\acm\zju\1048\financialmanagement.cpp 7
Error 8 error C2784: 'std::basic_ostream<char,_Traits> &std::eek:perator <<(std::basic_ostream<char,_Traits> &,const unsigned char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream' c:\acm\zju\1048\financialmanagement.cpp 7
Error 9 error C2784: 'std::basic_ostream<char,_Traits> &std::eek:perator <<(std::basic_ostream<char,_Traits> &,signed char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream' c:\acm\zju\1048\financialmanagement.cpp 7
Error 10 error C2784: 'std::basic_ostream<char,_Traits> &std::eek:perator <<(std::basic_ostream<char,_Traits> &,signed char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream' c:\acm\zju\1048\financialmanagement.cpp 7
Error 11 error C2784: 'std::basic_ostream<char,_Traits> &std::eek:perator <<(std::basic_ostream<char,_Traits> &,signed char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream' c:\acm\zju\1048\financialmanagement.cpp 7
Error 12 error C2784: 'std::basic_ostream<char,_Traits> &std::eek:perator <<(std::basic_ostream<char,_Traits> &,signed char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream' c:\acm\zju\1048\financialmanagement.cpp 7
Error 13 error C2784: 'std::basic_ostream<char,_Traits> &std::eek:perator <<(std::basic_ostream<char,_Traits> &,const signed char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream' c:\acm\zju\1048\financialmanagement.cpp 7
Error 14 error C2784: 'std::basic_ostream<char,_Traits> &std::eek:perator <<(std::basic_ostream<char,_Traits> &,const signed char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream' c:\acm\zju\1048\financialmanagement.cpp 7
Error 15 error C2784: 'std::basic_ostream<char,_Traits> &std::eek:perator <<(std::basic_ostream<char,_Traits> &,const signed char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream' c:\acm\zju\1048\financialmanagement.cpp 7
Error 16 error C2784: 'std::basic_ostream<char,_Traits> &std::eek:perator <<(std::basic_ostream<char,_Traits> &,const signed char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream' c:\acm\zju\1048\financialmanagement.cpp 7
Error 17 error C2784: 'std::basic_ostream<_Elem,_Traits> &std::eek:perator <<(std::basic_ostream<_Elem,_Traits> &,_Elem)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::istream' c:\acm\zju\1048\financialmanagement.cpp 7
Error 18 error C2784: 'std::basic_ostream<_Elem,_Traits> &std::eek:perator <<(std::basic_ostream<_Elem,_Traits> &,_Elem)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::istream' c:\acm\zju\1048\financialmanagement.cpp 7
Error 19 error C2784: 'std::basic_ostream<_Elem,_Traits> &std::eek:perator <<(std::basic_ostream<_Elem,_Traits> &,_Elem)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::istream' c:\acm\zju\1048\financialmanagement.cpp 7
Error 20 error C2784: 'std::basic_ostream<_Elem,_Traits> &std::eek:perator <<(std::basic_ostream<_Elem,_Traits> &,_Elem)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::istream' c:\acm\zju\1048\financialmanagement.cpp 7
Error 21 error C2784: 'std::basic_ostream<_Elem,_Traits> &std::eek:perator <<(std::basic_ostream<_Elem,_Traits> &,const _Elem *)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::istream' c:\acm\zju\1048\financialmanagement.cpp 7
Error 22 error C2784: 'std::basic_ostream<_Elem,_Traits> &std::eek:perator <<(std::basic_ostream<_Elem,_Traits> &,const _Elem *)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::istream' c:\acm\zju\1048\financialmanagement.cpp 7
Error 23 error C2784: 'std::basic_ostream<_Elem,_Traits> &std::eek:perator <<(std::basic_ostream<_Elem,_Traits> &,const _Elem *)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::istream' c:\acm\zju\1048\financialmanagement.cpp 7
Error 24 error C2784: 'std::basic_ostream<_Elem,_Traits> &std::eek:perator <<(std::basic_ostream<_Elem,_Traits> &,const _Elem *)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::istream' c:\acm\zju\1048\financialmanagement.cpp 7
Error 25 error C2784: 'std::basic_ostream<char,_Traits> &std::eek:perator <<(std::basic_ostream<char,_Traits> &,char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream' c:\acm\zju\1048\financialmanagement.cpp 7
Error 26 error C2784: 'std::basic_ostream<char,_Traits> &std::eek:perator <<(std::basic_ostream<char,_Traits> &,char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream' c:\acm\zju\1048\financialmanagement.cpp 7
Error 27 error C2784: 'std::basic_ostream<char,_Traits> &std::eek:perator <<(std::basic_ostream<char,_Traits> &,char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream' c:\acm\zju\1048\financialmanagement.cpp 7
Error 28 error C2784: 'std::basic_ostream<char,_Traits> &std::eek:perator <<(std::basic_ostream<char,_Traits> &,char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream' c:\acm\zju\1048\financialmanagement.cpp 7
Error 29 error C2784: 'std::basic_ostream<char,_Traits> &std::eek:perator <<(std::basic_ostream<char,_Traits> &,const char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream' c:\acm\zju\1048\financialmanagement.cpp 7
Error 30 error C2784: 'std::basic_ostream<char,_Traits> &std::eek:perator <<(std::basic_ostream<char,_Traits> &,const char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream' c:\acm\zju\1048\financialmanagement.cpp 7
Error 31 error C2784: 'std::basic_ostream<char,_Traits> &std::eek:perator <<(std::basic_ostream<char,_Traits> &,const char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream' c:\acm\zju\1048\financialmanagement.cpp 7
Error 32 error C2784: 'std::basic_ostream<char,_Traits> &std::eek:perator <<(std::basic_ostream<char,_Traits> &,const char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream' c:\acm\zju\1048\financialmanagement.cpp 7
Error 33 error C2784: 'std::basic_ostream<_Elem,_Traits> &std::eek:perator <<(std::basic_ostream<_Elem,_Traits> &,char)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::istream' c:\acm\zju\1048\financialmanagement.cpp 7
Error 34 error C2784: 'std::basic_ostream<_Elem,_Traits> &std::eek:perator <<(std::basic_ostream<_Elem,_Traits> &,char)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::istream' c:\acm\zju\1048\financialmanagement.cpp 7
Error 35 error C2784: 'std::basic_ostream<_Elem,_Traits> &std::eek:perator <<(std::basic_ostream<_Elem,_Traits> &,char)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::istream' c:\acm\zju\1048\financialmanagement.cpp 7
Error 36 error C2784: 'std::basic_ostream<_Elem,_Traits> &std::eek:perator <<(std::basic_ostream<_Elem,_Traits> &,char)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::istream' c:\acm\zju\1048\financialmanagement.cpp 7
Error 37 error C2784: 'std::basic_ostream<_Elem,_Traits> &std::eek:perator <<(std::basic_ostream<_Elem,_Traits> &,const char *)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::istream' c:\acm\zju\1048\financialmanagement.cpp 7
Error 38 error C2784: 'std::basic_ostream<_Elem,_Traits> &std::eek:perator <<(std::basic_ostream<_Elem,_Traits> &,const char *)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::istream' c:\acm\zju\1048\financialmanagement.cpp 7
Error 39 error C2784: 'std::basic_ostream<_Elem,_Traits> &std::eek:perator <<(std::basic_ostream<_Elem,_Traits> &,const char *)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::istream' c:\acm\zju\1048\financialmanagement.cpp 7
Error 40 error C2784: 'std::basic_ostream<_Elem,_Traits> &std::eek:perator <<(std::basic_ostream<_Elem,_Traits> &,const char *)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::istream' c:\acm\zju\1048\financialmanagement.cpp 7
Error 41 error C2676: binary '<<' : 'std::istream' does not define this operator or a conversion to a type acceptable to the predefined operator c:\acm\zju\1048\financialmanagement.cpp 7
 
Just some addition:
The program above was created as an windows console program with no precompiled header in vs2k5. thanks
 
I'm not sure why it does it, but I did notice that it tried every overload of operator<<() 4 times.
I'd guess it's trying to find a version of operator<<() that matches what you're trying to do, but why it does it 4 times and why it feels the need to tell you every single time it fails to find a match -- I don't have the slightest clue.

You could spend days (weeks, months...) trying to figure out why it does it, or you can simply accept the fact that it does very strange things that you have no control over... ;-)
 
We pay off templates old scores.

No intrinsic stream i/o operators in C++. The compiler does not know anything about simplest thing - do not try output ops on input streams. It deduces STL templates (implementation-dependent) and reports its troubles step by step. As usually it generates totally incomprehensible error/warning messages (not only in that cin>> case). The C++ has a great semantic gap between basic and generic programming parts. Honestly, I do not divide the C++ founder(s) delights on templates (delayed-action bomb placed in the language body;)...

May be we will see some improvements in new Standard but now I 100% agree with excellent cpjust's advice: you can simply accept the fact that it does very strange things that you have no control over...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top