Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a C++ program that finds all instances of a string in an input text file, replaces them with another string, and writes the result
Write a C++ program that finds all instances of a string in an input text file, replaces them with another string, and writes the result to an output file. At the start of the program, prompt the user to input the string that they want to find by printing "Find: " and read the input string. Then, prompt the user to input the replacement string by printing "Replace with:n" and read the input string The following input/output pairs assume that the input text file reads as follows "In C and C++, problems may be faced if two (or more) include files both in turn include the same third file." (a) Find: include Replace with: EXCLUDE Resulting output file: "In C and C++, problems may be faced if two (or more) EXCLUDE files both in turn EXCLUDE the same third file. (b) Find: C++ Replace with: LANGUAGE Resulting output file: "In C and C++, problems may be faced if two (or more) include files both in turn include the same third file." (c) Find: C++, Replace with: LANGUAGE Resulting output file: "In C and LANGUAGE problems may be faced if two (or more) include files both in turn include the same third file." Note: You must write your code in a source file named find replace.cpp. In your code, you must read from a text file named text in.txt and write to a text file named text out.txt You are provided an example input text file to test your code. Use the string type that is accessible when you include . Use cin to read input from the user (make sure to include ). Use file input and output streams to read from and write to the files (make sure to inlude )
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started