Program crashing when a string is entered

I just wrote a find and replace function, but it doesn't seem to work properly. Here is the code that I am using:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <string>
using namespace std;
string replace(string a, string b, string c);
int main(){
    string a;
    getline(cin,a);
    cout<<endl;
    for(int aa=0;aa<a.length();aa++){
        a=replace(a,"a","1");
    }
    cout<<a;
    system("pause");
    return 0;
}
string replace(string a, string b, string c){
    a.replace(a.find(b), c.length(), c);
    return a;
}


When I run the program and type in a string, I get an error that says "This application has requested the Runtime to terminate it in an unusual way. Please contact the applications support team for more information." What does this error mean, what causes it and how can I fix it?
Last edited on
¿what if there is no substring?
use some other name for your funsction, like myreplace
Topic archived. No new replies allowed.