Printing all the permutations of a string in alphabetical order It is a code eval challenge question https://www.codeeval.com/open_challenges/14/.
My answer was accepted, and I modified my code again to improve it. Please let me know is it possible to improve it more.

#include &lt;iostream&gt;
#include&lt;fstream&gt;
#include&lt;algorithm&gt;
#include&lt;string&gt;

void create_permute( std::string &amp;record )
{
    if( !record.empty() ) 
    {
        std::sort( record.begin(), record.end() );
        bool flag=0;
        do{
            if( flag )
            {
                std::cout&lt;&lt;",";
            }
            flag = 1;
            std::cout &lt;&lt; record;
        } while( std::next_permutation( record.begin(), record.end() ) );
        std::cout &lt;&lt; "\n";
    }
}
void readInputFile( std::string filename ) 
{

    std::ifstream infile;
    infile.open( filename );
    std::string record;
    while( std::getline( infile,record ) )
    {         
       create_permute( record );
    }
}

int main( int argc, char* argv[] )
{
    if( argc &lt; 2 )
    {
        std::cout &lt;&lt; "usage: filesize filename" &lt;&lt; "\n";
        exit( 0 );
    }
    std::ios_base::sync_with_stdio( false );
    readInputFile( argv[ 1 ] );

    return 0;
}
A boolean tested each time, and firing just once on the first iteration is unaesthetic (and a waste of time). Consider instead

    std::cout &lt;&lt; record;
    while (std::next_permutation(record.begin(), record.end())) {
        std::cout &lt;&lt; ',' &lt;&lt; record;
    }
    std::cout &lt;&lt; '\n';


Otherwise looks good. Congratulations for not using namespace std.