将集合附加到另一个集合
有没有比遍历每个元素更好的方法将一个集合附加到另一个集合?
Is there a better way of appending a set to another set than iterating through each element ?
我有:
set<string> foo ;
set<string> bar ;
.....
for (set<string>::const_iterator p = foo.begin( );p != foo.end( ); ++p)
bar.insert(*p);
有没有更有效的方法来做到这一点?
Is there a more efficient way to do this ?
推荐答案
可以插入范围:
bar.insert(foo.begin(), foo.end());
相关文章