Remove Text Before Marker From File

#include <fstream>			//Used for EventsToSendQueue
#include <unistd.h>			//Used for EventsToSendQueue

	string next_line;
	size_t find_result;
	bool found_marker = false;
	string EventsFilePath_Temp;
	string s_temp;
	
	EventsFilePath_Temp = EventsFilePath + ".temp";
	
	
	//----- OPEN THE FILES -----
	std::ifstream ifstream1(EventsFilePath.c_str());
	std::ofstream ofstream1(EventsFilePath_Temp.c_str(), std::ios_base::out);				//Overwrite an existing file if present
	if ( (ifstream1.is_open()) && (ofstream1.is_open()) )
	{
		while (getline(ifstream1, next_line))
		{
			//----- GET NEXT LINE -----
			if (found_marker)
			{
				ofstream1 << next_line << "\n";				//The "\n" is stripped by getline()
			}
			
			if ((find_result = next_line.find("[EVENT_END_YqzlQ2W4GOrkWr4qH]")) != string::npos)
			{
				//----- MARKER FOUND -----
				found_marker = true;
				s_temp = next_line.substr((find_result + 29));
				if (s_temp.length() > 0)
					ofstream1 << s_temp << "\n";				//The "\n" is stripped by getline()
			}
		}
		//----- CLOSE THE FILES -----
		ifstream1.close();
		ofstream1.close();
		
		//----- OVERWRITE THE OLD FILE WITH THE NEW FILE -----
		unlink(EventsFilePath.c_str());
		rename(EventsFilePath_Temp.c_str(), EventsFilePath.c_str());
		
	}