From 3492f9827d15bbe98e22398834770e9c89f454d9 Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Tue, 15 Mar 2022 19:34:23 +0200 Subject: Create replaceInFile.cpp --- Sem. 03/replaceInFile.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Sem. 03/replaceInFile.cpp (limited to 'Sem. 03/replaceInFile.cpp') diff --git a/Sem. 03/replaceInFile.cpp b/Sem. 03/replaceInFile.cpp new file mode 100644 index 0000000..67cb67f --- /dev/null +++ b/Sem. 03/replaceInFile.cpp @@ -0,0 +1,24 @@ +#include +#include +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); +} -- cgit v1.3.1-23-gd82d