|
试了好几次,还是不知道错在哪里,以下是部分代码:
#include <iostream.h>
#include <strstream.h>
#include <stdio.h>
//------
class intarray{
enum {sz=5};
int i[sz];
public:
......
friend ostream&
operator<<(ostream& os,const intarray& ia);
friend istream&
operator>>(istream& is,const intarray& ia);
};
ostream& operator<<(ostream& os,const intarray& ia){
......
};
istream& operator>>(istream& is,const intarray& ia){
......
};
main()
{
istrstream input("12,23,34,45,56");
intarray I;
input >> I;
I[4]=-1;
cout<<I;
}
编译显示(好像挺多,其实关键的不多):
[zhu@nobody c++]$ g++ opr1.cpp -o opr1
In file included from /usr/include/c++/3.2.2/backward/iostream.h:31,
from opr1.cpp:3:
/usr/include/c++/3.2.2/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated.
opr1.cpp: In function `std::istream& operator>>(std::istream&, const
intarray&)':
opr1.cpp:40: ambiguous overload for `std::basic_istream<char,
std::char_traits<char> >& >> const int&' operator
/usr/include/c++/3.2.2/bits/istream.tcc:83: candidates are:
std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT,
_Traits>:perator>>(std::basic_istream<_CharT,
_Traits>&(*)(std::basic_istream<_CharT, _Traits>&)) [with _CharT = char,
_Traits = std::char_traits<char>] <near match>
/usr/include/c++/3.2.2/bits/istream.tcc:92:
std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT,
_Traits>:perator>>(std::basic_ios<_CharT,
_Traits>&(*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits
= std::char_traits<char>] <near match>
/usr/include/c++/3.2.2/bits/istream.tcc:101:
std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT,
_Traits>:perator>>(std::ios_base&(*)(std::ios_base&)) [with _CharT = char,
_Traits = std::char_traits<char>] <near match>
/usr/include/c++/3.2.2/bits/istream.tcc:483:
std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT,
_Traits>:perator>>(std::basic_streambuf<_CharT, _Traits>*) [with _CharT =
char, _Traits = std::char_traits<char>] <near match>
/usr/include/c++/3.2.2/istream:255: std::basic_istream<char,
_Traits>& std:perator>>(std::basic_istream<char, _Traits>&, signed char*)
[with _Traits = std::char_traits<char>] <near match>
/usr/include/c++/3.2.2/istream:250: std::basic_istream<char,
_Traits>& std:perator>>(std::basic_istream<char, _Traits>&, unsigned
char*) [with _Traits = std::char_traits<char>] <near match>
[zhu@nobody c++]$ |
|