求救:我初学c++,写了一段程序,老是过不去
下面是部分程序段,请大虾一定帮忙啊
前面已经有:
int nSize = 0 ; vector<string> strOtherName ;
………
ifstream namedelete ( "name.dat" , ios::in |ios::out );
………
namedelete.close() ;后面的程序中:
namedelete.open ( "name.dat" , ios::trunc | ios::in | ios::out ) ;
for ( nSize = 0 ; nSize < strOtherName.size () ; ++nSize ) {
/*error*/ namedelete << strOtherName[nSize] << endl ;
}
error C2676: binary '<<' : 'class std::basic_ifstream<char,struct std::char_traits<char> >' does not define this operator or a conversion to a type acceptable to the predefined operator
执行 cl.exe 时出错. error C2784: 'class std::basic_ostream<_E,_Tr> &__cdecl std::operator <<(class std::basic_ostream<_E,_Tr> &,const unsigned char *)' : could not deduce template argument for 'class std::basic_ostream<_E,_
Tr> &' from 'class std::basic_ifstream<char,struct std::char_traits<char> >'
将strOtherName[nSize]改为(char)strOtherName[nSize]还是不行,还有如下错误:
error C2440: 'type cast' : cannot convert from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'char'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
执行 cl.exe 时出错.是哪里错了?应该改哪里啊?
下面是部分程序段,请大虾一定帮忙啊
前面已经有:
int nSize = 0 ; vector<string> strOtherName ;
………
ifstream namedelete ( "name.dat" , ios::in |ios::out );
………
namedelete.close() ;后面的程序中:
namedelete.open ( "name.dat" , ios::trunc | ios::in | ios::out ) ;
for ( nSize = 0 ; nSize < strOtherName.size () ; ++nSize ) {
/*error*/ namedelete << strOtherName[nSize] << endl ;
}
error C2676: binary '<<' : 'class std::basic_ifstream<char,struct std::char_traits<char> >' does not define this operator or a conversion to a type acceptable to the predefined operator
执行 cl.exe 时出错. error C2784: 'class std::basic_ostream<_E,_Tr> &__cdecl std::operator <<(class std::basic_ostream<_E,_Tr> &,const unsigned char *)' : could not deduce template argument for 'class std::basic_ostream<_E,_
Tr> &' from 'class std::basic_ifstream<char,struct std::char_traits<char> >'
将strOtherName[nSize]改为(char)strOtherName[nSize]还是不行,还有如下错误:
error C2440: 'type cast' : cannot convert from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'char'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
执行 cl.exe 时出错.是哪里错了?应该改哪里啊?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货