如何循環這個?C++循環std :: vector <std :: map <std :: string,std :: string>>
我已經嘗試過:
//----- code
std::vector<std::map<std::string, std::string> >::iterator it;
for (it = users.begin(); it != users.end(); it++) {
std::cout << *it << std::endl; // this is the only part i changed according to the codes below
}
//----- error
error: initializing argument 1 of ‘std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&&, const _Tp&) [with _CharT = char; _Traits = std::char_traits<char>; _Tp = std::map<std::basic_string<char>, std::basic_string<char> >]’
//----- code
std::cout << *it["username"] << std::endl;
//----- error
note: template argument deduction/substitution failed:
note: ‘std::map<std::basic_string<char>, std::basic_string<char> >’ is not derived from ‘const std::complex<_Tp>’
//----- code
std::cout << *it->second << std::endl; // also tried with parenthesis - second()
//----- error
error: ‘class std::map<std::basic_string<char>, std::basic_string<char> >’ has no member named ‘second’
//----- code
for(const auto& curr : it) std::cout << curr.first() << " = " << curr.second() << std::endl;
//----- error
error: unable to deduce ‘const auto&’ from ‘<expression error>’
,最後
//----- code
std::map<std::string, std::string>::iterator curr, end;
for(curr = it.begin(), end = it.end(); curr != end; ++curr) {
std::cout << curr->first << " = " << curr->second << std::endl;
}
//----- error
‘std::vector<std::map<std::basic_string<char>, std::basic_string<char> > >::iterator’ has no member named ‘begin‘ & ‘end’
我希望我給出一個明確的細節..然後上面是下面的代碼是錯誤..而目前我的腦子一片空白。
和抱歉這個..
我已經讓這種類型的工作:std::map<int, std::map<std::string, std::string> >
和IM嘗試使用向量作爲一個選項。
THANK YOU VERY MUCH ...我想你所有的答案,這一切工作.. – xeroblast 2015-02-12 06:28:29