struct user
{
vector<size_t> follower;
vector<size_t> following;
};
int main ()
{
vector< user > node ( 100 );
// Pushing back some indices of other nodes in some node[x].follower and node[x].following
size_t i = 2;
for ( size_t const& j : node[i].follower )
node[j].following.erase( remove( node[j].following.begin(), node[j].following.end(), i ), node[j].following.end() );
}
在 C++ 中,我创建了struct user
, where 向量follower
并将following
索引存储到属于vector node
. 在最后一个for
循环中,我想销毁其他用户的所有索引i
(指的是特定的user i
);不幸的是,使用 C++11,我得到了这个错误:vector follower
following
gcc/4.7.2
error: cannot convert 'std::vector<long unsigned int>::iterator {aka __gnu_cxx::__normal_iterator<long unsigned int*, std::vector<long unsigned int> >}' to 'const char*' for argument '1' to 'int remove(const char*)'
我还尝试了在循环代码中使用for
的迭代器循环,但我仍然得到类似的错误。for ( vector<size_t>::iterator it = node[i].follower.begin(); it != node[i].follower.end(); ++it )
*it
我不知道该怎么办。