I have a function that swaps two chars, in a file, at a time, which works, however if i try to use the function more than once the previous swap i made will be wiped from the text file and the original text in now back in, therefore the second change will seem as my first. how can i resolve this?
void swapping_letters()
{
    ifstream inFile("decrypted.txt");   
    ofstream outFile("swap.txt");
    char a;
    char b;
    vector<char> fileChars;
    if (inFile.is_open())
    {
        cout<<"What is the letter you want to replace?"<<endl;
        cin>>a;             
        cout<<"What is the letter you want to replace it with?"<<endl;
        cin>>b;
        while (inFile.good())
        {
            char c;
            inFile.get(c);
            fileChars.push_back(c);
        }                   
        replace(fileChars.begin(),fileChars.end(),a,b);
    }
    else
    {
        cout<<"Please run the decrypt."<<endl;
    }
    for(int i = 0; i < fileChars.size(); i++)
    {
        outFile<<fileChars[i];
    }
}
 
     
    