使用std :: transform,最好使用begin()或back_inserter()?

时间:2016-06-25 20:26:38

标签: c++

This page使用<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <video id="video" autoplay muted src="http://webm.land/media/KLNV.webm" width="400" height="200" />this one and many others建议使用begin()。我现在已经读了一个小时了,找不到任何坚实的理由来使用其中一个,或者有什么区别。有人能指出我正确的方向吗?

1 个答案:

答案 0 :(得分:3)

那些完全不同的东西:

std::string a = "12345", b = "67890", c = b;

std::transform(a.begin(), a.end(), b.begin(), [](char ch) { return ch; });
// b is now "12345"

std::transform(a.begin(), a.end(), std::back_inserter(c), [](char ch) { return ch; });
// c is now "6789012345"