C++遇到一个奇怪的问题
请教各位大侠:
程序很简单,照书上打的,如下:
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
//----------------------------------
int main(){
ifstream in( "string.txt ");
for(string s,t; in> > s> > t; ){ //这行是第14行,对应第一个错误
sort(s.begin(), s.end());
sort(t.begin(), t.end());
cout < < "yes ";
cout < <(s==t ? "yes\n " : "no\n ");
}
}//=================================
编译后报错:大家看一下第一个错就好了,我觉的第一个解决了就都解决了。
D:\incoming\f0612\f0612.cpp(14) : error C2679: binary '> > ' : no operator defined which takes a right-hand operand of type 'class std::basic_string <char,struct std::char_traits <char> ,class std::allocator <char> > ' (or there is no acceptable conve
rsion)
D:\incoming\f0612\f0612.cpp(18) : error C2784: 'bool __cdecl std::operator ==(const class std::istream_iterator <_U,_E,_Tr> &,const class std::istream_iterator <_U,_E,_Tr> &) ' : could not deduce template argument for 'const class std::istream_ite
rator <_U,_E,_Tr> & ' from 'class std::basic_string <char,struct std::char_traits <char> ,class std::allocator <char> > '
D:\incoming\f0612\f0612.cpp(18) : error C2784: 'bool __cdecl std::operator ==(const class std::reverse_bidirectional_iterator <_BI,_Ty,_Rt,_Pt,_D> &,const class std::reverse_bidirectional_iterator <_BI,_Ty,_Rt,_Pt,_D> &) ' : could not deduce templ
ate argument for 'const class std::reverse_bidirectional_iterator <_BI,_Ty,_Rt,_Pt,_D> & ' from 'class std::basic_string <char,struct std::char_traits <char> ,class std::allocator <char> > '
D:\incoming\f0612\f0612.cpp(18) : error C2784: 'bool __cdecl std::operator ==(const class std::allocator <_Ty> &,const class std::allocator <_U> &) ' : could not deduce template argument for 'const class std::allocator <_Ty> & ' from 'class std::bas
ic_string <char,struct std::char_traits <char> ,class std::allocator <char> > '
D:\incoming\f0612\f0612.cpp(18) : error C2784: 'bool __cdecl std::operator ==(const class std::istreambuf_iterator <_E,_Tr> &,const class std::istreambuf_iterator <_E,_Tr> &) ' : could not deduce template argument for 'const class std::istreambuf_
iterator <_E,_Tr> & ' from 'class std::basic_string <char,struct std::char_traits <char> ,class std::allocator <char> > '
D:\incoming\f0612\f0612.cpp(18) : error C2784: 'bool __cdecl std::operator ==(const class std::reverse_iterator <_RI,_Ty,_Rt,_Pt,_D> &,const class std::reverse_iterator <_RI,_Ty,_Rt,_Pt,_D> &) ' : could not deduce template argument for 'const clas
s std::reverse_iterator <_RI,_Ty,_Rt,_Pt,_D> & ' from 'class std::basic_string <char,struct std::char_traits <char> ,class std::allocator <char> > '
D:\incoming\f0612\f0612.cpp(18) : error C2784: 'bool __cdecl std::operator ==(const struct std::pair <_T1,_T2> &,const struct std::pair <_T1,_T2> &) ' : could not deduce template argument for 'const struct std::pair <_T1,_T2> & ' from 'class std::ba
sic_string <char,struct std::char_traits <char> ,class std::allocator <char> > '
D:\incoming\f0612\f0612.cpp(18) : error C2676: binary '== ' : 'class std::basic_string <char,struct std::char_traits <char> ,class std::allocator <char> > ' does not define this operator or a conversion to a type acceptable to the predefined operator
D:\incoming\f0612\f0612.cpp(20) : warning C4508: 'main ' : function should return a value; 'void ' return type assumed
Error executing cl.exe.
[解决办法]
#include <string>
[解决办法]
devCPP下没有错误
[解决办法]
呵呵,也奇怪了,devC++下没有错误,它不用包含string,哈哈