myStream.write(temp2.c_str(), 100); myStream << temp2 << endl;
Why do you write this to a file twice, and why do you tell him that βI love pizza with a big dishβ is 100 characters long? Just using the second line, you have to do what you want.
I think the reason the loop ends is because you write the file as you read it, which causes getline confusion. If the file is small, I would just read it all in stringstream , replacing the string you want to replace, and then write the entire stringstream file to the file. Changing a file in place is much more complicated.
Example:
#include <fstream>
Run as:
g++ example.cpp -o example ./example Hi.txt Hi 'I like deep dish pizza'
Brendan long
source share