C++ search and replace word in .txt file

Hello, I made a program that finds all the words in my .txt file and shows them to the screen, but now I want to make it so that I can pick a word from the .txt file and replace it with something else. For example :
teksts.txt has the words "dog, cat, bird" in it,
I want to choose the word "cat" and replace it with the word "rat".
Is there a simple way I can do it with useing this code as the base?
I really need the help :(

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main() {
    string line = " ";
    ifstream fails;

    fails.open("teksts.txt");
    while (getline (fails, line) )
		{
		 cout << line << '\n';
		}

    fails.close();
    std::cin.get();
    return 0;
}
Anyone ? :(
Topic archived. No new replies allowed.