I adapted most of the suggestions from answers for my previous question Printing all the permutations of a string in alphabetical order to rewrote my solution again. Please let me know any more changes required or any more suggestions.
#include <iostream>
#include<fstream>
#include<algorithm>
#include<string>
void create_permute( std::string& record )
{
std::sort( record.begin(), record.end() );
std::cout<<record;
while( std::next_permutation( record.begin(), record.end() ) )
{
std::cout<<","<<record;
}
std::cout << "\n";
}
void readInputFile( std::string filename )
{
std::ifstream infile(filename);
std::string record;
while( std::getline( infile,record ) )
{
create_permute( record );
}
infile.close();
}
int main( int argc, char* argv[] )
{
if( argc < 2 )
{
std::cout << "usage: filesize filename" << "\n";
exit( 0 );
}
std::ios_base::sync_with_stdio( false );
readInputFile( argv[ 1 ] );
return 0;
}