Click here to Skip to main content
12,252,552 members (62,814 online)
Click here to Skip to main content

Stats

224.2K views
5K downloads
65 bookmarked
Posted

Combinations in C++

, 12 Apr 2016 CPOL
An article on finding combinations
#include<iostream>
#include<vector>
#include<string>
#include"combination.h"

using namespace std;
using namespace stdcomb;

/*
//using pointers
int main()
{
  char n[]="2345678";
  char r[]="678";
  
  do
  {
    cout<<r<<endl;    
  }
  while(prev_combination(n,n+7,r,r+3) );
  return 0;
}
*/

//using iterators
int main()
{
  vector<string> n;
  n.push_back("1");
  n.push_back("2");
  n.push_back("3");
  n.push_back("4");
  n.push_back("5");
  n.push_back("6");
  n.push_back("7");
  n.push_back("8");
  vector<string> r;
  r.push_back("6");
  r.push_back("7");
  r.push_back("8");
  
  do
  {
    for(vector<string>::iterator it=r.begin();it!=r.end();++it)
      cout<<*it;
    cout<<endl;    
  }
  while( prev_combination(n.begin(),n.end(),r.begin(),r.end() ) );
  return 0;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Shao Voon Wong
Software Developer (Senior)
Singapore Singapore
IT Certifications

  • IT Infrastructure Library Foundational (ITIL v3)
  • Scrum Alliance Certified Scrum Master (CSM)
  • EC-Council Certified Secure Programmer (ECSP) .NET
  • EC-Council Certified Ethical Hacker (CEH)
  • EC-Council Certified Security Analyst (ECSA)
  • Certified Secure Software Lifecycle Professional (CSSLP)

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160426.1 | Last Updated 12 Apr 2016
Article Copyright 2016 by Shao Voon Wong
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid