0
void webparser(const string siteurl,string filename)
{
stringstream ss;
ss << "lynx -dump '" << siteurl << "'" > filename;
system(ss.str().c_str());
}
如何在上面的例子中使用filename而不是file.txt?C++這個函數有什麼問題
最初我對SS線是
ss << "lynx -dump '" << siteurl << "' > file.txt";
但我決定改變它從參數使用的價值,所以我增加了文件名。
下面是我的錯誤信息
main.cpp: In function ‘void webparser(std::string, std::string)’:
main.cpp:244:46: error: no match for ‘operator>’ in ‘std::operator<< [with _Traits = std::char_traits<char>]((* & std::operator<< [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]((* & std::operator<< [with _Traits = std::char_traits<char>]((* & ss.std::basic_stringstream<char>::<anonymous>.std::basic_iostream<char>::<anonymous>), ((const char*)"lynx -dump \'"))), (* & siteurl))), ((const char*)"\'")) > filename’
main.cpp:244:46: note: candidates are:
/usr/include/c++/4.6/bits/stl_pair.h:220:5: note: template<class _T1, class _T2> bool std::operator>(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)
/usr/include/c++/4.6/bits/stl_iterator.h:303:5: note: template<class _Iterator> bool std::operator>(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
/usr/include/c++/4.6/bits/stl_iterator.h:353:5: note: template<class _IteratorL, class _IteratorR> bool std::operator>(const std::reverse_iterator<_IteratorL>&, const std::reverse_iterator<_IteratorR>&)
/usr/include/c++/4.6/bits/basic_string.h:2547:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator>(const std::basic_string<_CharT, _Traits, _Alloc>&, const std::basic_string<_CharT, _Traits, _Alloc>&)
/usr/include/c++/4.6/bits/basic_string.h:2559:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator>(const std::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)
/usr/include/c++/4.6/bits/basic_string.h:2571:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator>(const _CharT*, const std::basic_string<_CharT, _Traits, _Alloc>&)
/usr/include/c++/4.6/bits/stl_iterator.h:842:5: note: template<class _Iterator, class _Container> bool __gnu_cxx::operator>(const __gnu_cxx::__normal_iterator<_Iterator, _Container>&, const __gnu_cxx::__normal_iterator<_Iterator, _Container>&)
/usr/include/c++/4.6/bits/stl_iterator.h:836:5: note: template<class _IteratorL, class _IteratorR, class _Container> bool __gnu_cxx::operator>(const __gnu_cxx::__normal_iterator<_IteratorL, _Container>&, const __gnu_cxx::__normal_iterator<_IteratorR, _Container>&)
make: *** [main.o] Error 1
這個警告的重要部分是在最開始的時候:「錯誤:'operator'不匹配''。」編譯器不知道如何處理'>'。 – 2012-07-26 17:03:15
你當然想要確保siteurl中沒有任何'''字符。 – Eclipse 2012-07-26 17:05:45