Q:

Finding Randomly Order Substring in String

For my first part of the question, We have given a long string of input and we have to count the occurrence for it. 
For eg. 
Input = AXBHAAGHXAXBH
Find = AXBH
Output = 2

This can be achieved by using the string.find("term") loop. Eg. 
#include <string>
#include <iostream>
int main()
{
   int occurrences = 0;
   std::string::size_type pos = 0;
   std::string inputz = "AXBHAAGHXAXBH";
   std::string target = "AXBH";
   while ((pos = inputz.find(target, pos )) != std::string::npos) {
          ++ occurrences;
          pos += target.length();
   }
   std::cout << occurrences << std::endl;

}

However, I am not sure how to do the second part where, it needs to take into account the random structure:
Random structure refers to any orientation of our find. Important note: The find occurrences are always grouped together but can have different structure.
I do not want to use cases because some sample find are too big eg. Find AXBHNMB would have too many cases to consider and would prefer a more general approach.
Eg. AXBH is find, then AXHB is also acceptable for the occurence

A proper example:
Input = AXBHAAGHXAXBH**ABHX**NBMN**AHBX**
Find = AXBH
Output = 4

Prefer if you please code it for the given example with link to explanation/explanation to any new function you use.

A:

You are correct that checking all permutations would take a lot of time.  Fortunately we don't need to do that.  What we can do is store the string to find in a std::map<char, int>/std::unordered_map<char, int> and then grab sub strings from the string to search through, convert those into the same type of map and see if those maps are equal.  This lets use compare without caring about the order, it just makes sure we have the correct amount of each character.  So we would have something like
int main()
{
    std::string source = "AHAZHBCHZCAHAHZEHHAAZHBZBZHHAAZAAHHZBAAAAHHHHZZBEWWAAHHZ ";
    std::string string_to_find = "AAHHZ";
    int counter = 0;

    // build map of the characters to find
    std::unordered_map<char, int> to_find;
    for (auto e : string_to_find)
        ++to_find[e];

    // loop through the string, grabbing string_to_find chunks and comparing
    for (std::size_t i = 0; i < source.size() - string_to_find.size();)
    {
        std::unordered_map<char, int> part;
        for (std::size_t j = i; j < string_to_find.size() + i; ++j)
            ++part[source[j]];

        if (to_find == part)
        {
            ++counter;
            i += string_to_find.size();
        }
        else
        {
            ++i;
        }
    }

    std::cout << counter;
}

