gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 00:02:10 26 4
gpt4 key购买 nike

This pagethis one and many others 时使用 begin()建议使用 std::back_inserter。我已经读了一个小时了,但找不到任何充分的理由来使用一个而不是另一个,或者有什么区别。谁能指出我正确的方向?

最佳答案

它们做完全不同的事情:

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"

关于c++ - 使用 std::transform,最好使用 begin() 或 back_inserter()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38032684/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com