blob: e1a6338949b52ebfdac7ce3b8cb31ccb030156a4 (
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
25
26
27
28
29
30
31
32
33
|
#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);
if(!file.is_open())
{
std::cout << "Error while opening the file!" << std::endl;
return -1;
}
replaceInFile('a', 'X', file);
return 0;
}
|