Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ problem HW6Prob1.txt Problem 1. Find and Replace Write a program to search f

ID: 3777469 • Letter: C

Question

C++ problem

HW6Prob1.txt

Problem 1. Find and Replace Write a program to search for a user defined string in a text file and replace it with another user defined string. From your main function, read a text file and ask the user for the string to search and the string to replace with. Write a programmer defined function that accepts a file stream object and two strings, and searches for the first string in the text file. If there is a match, this function will replace the matched string with a second string. Choose any implementation you desire. Use HW6Probl.txt' as the input file for this program.

Explanation / Answer

#include <iostream>
#include <fstream.h>
#include <string.h>

int main(){
ostream outFile("New.txt");
istream readFile("HW6Prob1.txt");
string readout;
string search;
string replace;
while(getline(readFile,readout)){
if(readout == search){
outFile << replace;
}
else {
outFile << readout;
}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote