In C++ the Standard Template Library provides us with std::next_permutation to easily implement this.
#include <iostream>
#include <algorithm>
#include <iterator>
#include <string.h>
int main()
{
char str[] = "abcd";
const size_t len = strlen( str );
do
{
std::copy( str,
str + len,
std::ostream_iterator<char>( std::cout ) );
std::cout << std::endl;
}
while ( std::next_permutation( str, str + len ) );
return 0;
}