#include <iostream>
#include <string>

int main() {
	std::string s = "AAABCAAABCDEAA";
	std::string::size_type start = 0, pos;
	while ((pos = s.find("AA", start)) != std::string::npos)
	{
		pos += 2;
		std::string s1 = s.substr(start, pos-start);
		// use s1 as needed...
		std::cout << s1 << std::endl;
		start = pos;
	}
	return 0;
}