c++, characters combination problem

This is a discussion on c++, characters combination problem within the C++ Programming forums, part of the General Programming Boards category; If there is a string, n characters e.g. input string = "abcde" How can I show all the their combinations ...

  1. #1
    Unregistered
    Guest

    c++, characters combination problem

    If there is a string, n characters
    e.g. input string = "abcde"

    How can I show all the their combinations ?
    e.g. abcde, abced, abecd.... etc.

    newstr = new string[instr.length()*instr.length()];
    for (i = 0; i < ???; i++)
    for (j = ?? ?????)

    thanks!!

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    155
    I hear there is a permutation function in the STL. Alternatively you can write one of your own using a set of nested loops.

  3. #3
    Unregistered
    Guest
    Sorry... Would you mind giving me more infomation??

    thx!

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    101
    Bjarne Stroustrup gives this as an example in 'The C++ Programming Language':
    Code:
    #include <iostream>
    #include <algorithm>
    using namespace std;
    
    int main() {
        char v[] = "abcd";
        cout << v << '\t';
        while(next_permutation(v, v+4)) {
            cout << v << '\t';
        }
    }
    - lmov

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. While loop with multiple characters
    By arctic_blizzard in forum C Programming
    Replies: 16
    Last Post: 09-20-2008, 12:25 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  3. Help with hw problem: counting characters in a string
    By pinkfloyd4ever in forum C++ Programming
    Replies: 11
    Last Post: 11-04-2007, 10:18 PM
  4. Problem with for loop calling external function
    By lordbubonicus in forum C Programming
    Replies: 2
    Last Post: 10-13-2007, 10:54 AM
  5. towers of hanoi problem
    By aik_21 in forum C Programming
    Replies: 1
    Last Post: 10-02-2004, 01:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21