我正在開發gsoap web服務,我正在檢索查詢的對象向量。我有兩種方法來實現它:首先通過簡單循環和迭代器。他們都沒有工作。std :: cout中'operator <<'不匹配
的錯誤是:
error: no match for
'operator<<'
in'std::cout mPer.MultiplePersons::info.std::vector<_Tp, _Alloc>::at<PersonInfo, std::allocator<PersonInfo> >(((std::vector<PersonInfo>::size_type)i))'
MultiplePersons mPer; // Multiple Person is a class, containing vector<PersonInfo> info
std::vector<PersonInfo>info; // PersonInfo is class having attributes Name, sex, etc.
std::vector<PersonInfo>::iterator it;
cout << "First Name: \t";
cin >> firstname;
if (p.idenGetFirstName(firstname, &mPer) == SOAP_OK) {
// for (int i = 0; i < mPer.info.size(); i++) {
// cout << mPer.info.at(i); //Error
//}
for (it = info.begin(); it != info.end(); ++it) {
cout << *it; // Error
}
} else p.soap_stream_fault(std::cerr);
}
很明顯,運營商cout
超載operator<<
的問題。我已經看到了與此有關的幾個問題,但沒有人幫助我。如果有人能提供一個具體的例子來解決這個問題,那將非常感激。 (請不要一概而論,我是C++的新手,我花了三天時間尋找解決方案。)
@Baum mit Augen,2013年3月16日提出這個問題,你說它已經有一個答案(2014年3月23日提出)。而不是標記其他問題重複,你標記了這一個。無法理解你的邏輯。 – Kahn 2017-03-06 12:12:40
在清理舊的常見問題時,詢問時間不再是主要標準。相反,Q/A的有用性是關鍵。我選擇了另一個,因爲它有一個實際的MCVE,所以答案更簡潔,因爲它們不需要首先提供一個示例類體。我覺得這對未來的訪問者來說更容易閱讀。 – 2017-03-06 13:01:42