簡體   English   中英

使用不帶std :: copy的插入迭代器

[英]using insert iterators without std::copy

我有一個插入迭代器和一個要插入的元素的迭代器,但不允許使用std::copy

這是我在c ++參考頁上找到的:

std::copy (bar.begin(),bar.end(),insert_it);

這也是我想要做的,但是我不能使用std::copy 還有另一種方法嗎?

auto first = bar.begin();
auto last = bar.end();
while (first!=last)
{
  *insert_it = *first;
  ++insert_it;
  ++first;
}

您提供的代碼將內容從bar.begin()移到bar.end()到插入迭代器中。 我對您使用insertstd::copy這個術語感到困惑,它不會插入任何內容,而只是復制內容。

要將元素實際插入容器中,可以使用以下命令:

your_container.insert(insert_it, bar.begin(),bar.end());

您可以在此處找到std::vector的示例http://en.cppreference.com/w/cpp/container/vector/insert/insert/

希望這會有所幫助,Raxvan。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM