map<string, vector<int>*> settings
for (auto el : settings)
{
for(auto i : el)
{
cout << i;
}
}
Run Code Online (Sandbox Code Playgroud)
我得到内部el:这个基于范围的'for'语句需要一个合适的begin函数,但没有找到.我该如何解决这个问题?
当你使用
map<string, vector<int>*> settings
for (auto el : settings)
{
}
Run Code Online (Sandbox Code Playgroud)
el是一个std::pair<const string, vector<int>*>.检查出的定义std::map::value_type在cppreference.com.
要从矢量中获取项目,您需要使用
map<string, vector<int>*> settings
for (auto el : settings)
{
for ( auto item : *(el.second) )
{
// Use item
}
}
Run Code Online (Sandbox Code Playgroud)
为避免不必要的复制std::pair,您可以使用auto const& el.
map<string, vector<int>*> settings
for (auto const& el : settings)
{
for ( auto item : *(el.second) )
{
// Use item
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
82 次 |
| 最近记录: |