欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 新车 > C++ STL find 用法

C++ STL find 用法

2025/6/8 14:34:33 来源:https://blog.csdn.net/zg260/article/details/141385296  浏览:    关键词:C++ STL find 用法

一:功能

        线性查找,返回第一个查找到的元素位置,若未找到返回容器 end() 迭代器(即最后一个元素之后的位置)。  

二:用法

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>int main() {std::string data = "I;am;learning;c++;language;";auto it = data.begin(), token = data.begin();std::vector<std::string> out;while ((token = find(it, data.end(), ';')) != data.end()) {out.push_back("");std::copy(it, token, std::back_inserter(out.back()));it = std::next(token);}for (auto &v : out)std::cout << std::quoted(v) << " ";std::cout << "\n";
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词