63,596
社区成员




#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std ;
void sub_set(int M,int N,vector<string>& vec)
{
typedef vector<char> StrVector ;
typedef StrVector::iterator StrVectorIt ;
typedef ostream_iterator<char> StrOstreamIt;
StrVector Pattern(M+N);
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<M+N;i++)
{
Pattern[i]=i<N?'0':'1';
}
cout << "Before calling next_permutation...\n" << "Pattern: " ;
for(it = start; it != end; it++)
cout << *it << " " ;
cout << "\n\n" ;
cout << "After calling next_permutation...." << endl ;
do
{
string str(start,end);
vec.push_back(str);
}while ( next_permutation(start, end));
}
//保存到vec中
void main()
{
vector<string> vec;
sub_set(5,3,vec);
copy(vec.begin(),vec.end(),ostream_iterator<string>(cout,"\n"));
}
ostream_iterator <int>(cout))
用cout去初始化一个ostream_iterator<int>对象;
你可以自己写一个函数将cout内容保存,函数返回嘛,