#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
static int n;
int lenstring(char a[])
{
for (n=0;a[n]!=NULL;n++);
return(n);
}
void main()
{
char a[40]:
int lenstring(char*);
cout<<"Give a string:"<<endl;
cin>>a;
n=lenstring(a);
cout<<"length of first token="<<n<<endl;
const int VECTOR_SIZE=n;
//Define a template class vector of strings
typedef vector<string>StrVector;
//Define an iterator for template class vector of strings
typedef StrVector::iterator StrVecotrIt;
//Define an ostream iterator for strings
typedef ostream_iterator<string>StrOstreamIt;
StrVector Pattern(VECTOR_SIZE);
StrVectorIt start,end,it;
StrOstreamIt outIt(cout,"");
start=Pattern.begin();//location of first
//element of pattern
end=Pattern.end();//one past the location last
//element of Pattern
{
for(int i=0;i<n;i++)
Pattern[i]=a[i];
}
cout<<"Before calling next_permutation...\n"<<"Pattern:";
for(it=start;it!=end;it++)
cout<<*it<<"";
cout<<"\n\n";
int counter=1;
cout<<"After calling next_permutation..."<<endl;
while (next_permutation(start,end))
{
copy(start,end,outlt);
counter++;
cout<<endl;
}
cout<<"counter:"<<counter<<endl; }
I bet you can. (That is don't just post a bunch of code saying that it's bad. Explain what id does and what you want it to do.)
Also, use [code] tags and indentation to make code readable.
it has compilation errors when the one that gave it to me said that it was right ...it gives at the exit all the permutations when the pattern is given..