c++ - 在 C++ 中使用单词作为分隔符拆分字符串

标签 c++ string

我有一个非常非常长的字符串!它中间有单词“post”,我想使用“post”作为分隔符来标记字符串!我遇到了 boost 库来使用 split_regex 或类似的东西来做到这一点!如果有人知道一种真正有效的方法,请告诉我

-谢谢

最佳答案

你可以看看Boost String Algorithms Library

#include <string>
#include <vector>
#include <algorithm>
#include <iterator>
#include <iostream>
#include <boost/algorithm/string/iter_find.hpp>
#include <boost/algorithm/string/finder.hpp>
int main()
{
    std::string input = "msg1foomsg2foomsg3";

    std::vector<std::string> v;
    iter_split(v, input, boost::algorithm::first_finder("foo"));

    copy(v.begin(), v.end(), std::ostream_iterator<std::string>(std::cout, " "));
    std::cout << std:endl;
}

关于c++ - 在 C++ 中使用单词作为分隔符拆分字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14719712/

相关文章:

c++ - 将 numpy 指针 (dtype=np.bool) 传递给 C++

c++ - 从 Visual Studio 2012 为 Windows 和 UNIX 机器编译项目

ruby - 检查散列是否有一个包含一些文本的键

c# - 在字符串中使用二进制数据时数据是 "lost"吗?

c - 字符串的倒三角形

c++ - 如何对 Mat 的单个坐标使用 warpPerspective

c++ - 为字符串值实现 cdbpp 库

c++ - 无法链接 ".o"目标文件

r - 如果 R 数据框中的列包含特定文本,则删除重复的观察值

java - 如果括号匹配则返回 true 的 boolean 方法