Since you are in C ++, do it in a C ++ way:
char a[] = { 0, 0, 0, 0xFC }; char Buffer[20000] = ... std::string needle(a, a + 4); std::string haystack(Buffer, Buffer + 20000); // or "+ sizeof Buffer" std::size_t n = haystack.find(needle); if (n == std::string::npos) { // not found } else { // position is n }
You can also use the algorithm to search for the array directly:
#include <algorithm>
Or, in C ++ 17, you can use a string view:
std::string_view sv(std::begin(Buffer), std::end(Buffer)); if (std::size_t n = sv.find(needle); n != sv.npos) { // found at position n } else { // not found }
source share