need help in figuring out the error message

Hello Everyone i am trying to write a program for printing all the combinations of a string.I do not want any help regarding the algorithm but i need help figuring out why this program is giving the error message
"First-chance exception at 0x761bc41f in word.exe: Microsoft C++ exception: std::out_of_range at memory location 0x0026f6b4..
Unhandled exception at 0x761bc41f in word.exe: Microsoft C++ exception: std::out_of_range at memory location 0x0026f6b4.." when i try to run this in MVS 2010
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

    #include<iostream>
    #include <stdio.h>
    #include <string>
    #include <stdlib.h>
    #include<conio.h>
    void combination(std::string input,int length,std::string buffer,int allowedno)
    {
    for(int i =allowedno;i<length;i++)
    {
    buffer.at(i)=input.at(i);
    std::cout << buffer<< '\n';
    if(i!=length)
    {
    combination(input,length,buffer,i+1);
    }
    buffer.erase(length-1);
    }
    }
    void combine(std::string input)
    {
    int length=input.size();
    //char *buffer = (char *)malloc(sizeof(char)*(length+1));
    std::string buffer(input);
    buffer.erase();
    combination(input,length,buffer,0);
    }
    void main()
    {
    std ::string input= "ABC";
    combine(input);
    getch();
    }
If you erase stuff from the string, then the length of the string you have in length is no longer valid. This probably results in several out of range access errors on your string.
Topic archived. No new replies allowed.