Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 03 / replaceInFile.cpp
blob: 67cb67fa6dbde4544582c4070a87bcbc327a30f4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <fstream>
using namespace std;

void replaceInFile(char ch, char ch2, fstream& file)
{
	while (!file.eof())
	{
		char currentSybmol = file.get();

		if (currentSybmol != ch)
			continue;

		file.seekp(-1, ios::cur);
		file.put(ch2);
		file.flush();
	}
}

int main()
{
	fstream file("treasureTrail.txt", ios::in | ios::out);
	replaceInFile('a', 'X', file);
}