#include <string>
#include <iostream>

void callback( std::string const& text )
{
	std::cout << text << "\n";
}

bool next_permuation( std::string& test_case,
					  std::string const& alphabet )
{
	for( std::size_t i = 0; i < test_case.length(); ++i )
	{
		if( test_case[i] == alphabet.back() )
		{
			if( i == test_case.length() -1 )
			{
				// letztes Zeichen läuft über -> Ende
				return false;
			}
			// Zeichen an aktueller Stelle ersetzen und Schleifendurchlauf fortsetzen
			test_case[i] = alphabet.front();
		}
		else
		{
			auto pos = alphabet.find( test_case[i] );
			if( pos == std::string::npos )
			{
				// Zeichen nicht im Alphabet? -> Ende
				return false;
			}
			// kein Überlauf, Zeichen ersetzen
			test_case[i] = alphabet[pos +1];
			return true;
		}
	}
	return false;
}

int main()
{
	std::string const alphabet = "ABC";
	std::size_t max_length = 3;

	for( std::size_t i = 1; i <= max_length; ++i )
	{
		std::string testcase( i, alphabet.front() );
		do
		{
			callback( testcase );
		}
		while( next_permuation( testcase, alphabet ) );
	}
	int z = 0;
}
