首页 > 解决方案 > Is there a function like find_last_of in std but not in string?

问题描述

I know there is function

string::find_last_of

But I want to process a large chunk of char* data. I don't want to assign the char* to a string.

I know there is a std function

std::find

But it only can find char* on positive sequence. Is there such a way to find in reverse order? If not in std, is there a way in boost?

标签: c++std

解决方案


std::find_end()

在范围 [first, last) 中搜索元素 [s_first, s_last) 的最后一个子序列。

例如

#include <algorithm>

char *data = ...;
char *data_end = data + size;
char toFind = ...;
char *pfind = &toFind;

char *found = std::find_end(data, data_end, pfind, pfind + 1);
if (found != data_end)
    ...

推荐阅读