#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream stream1("source.txt");
string line ;
ofstream stream2("target.txt");
while( std::getline( stream1, line ) )
{
stream2 << line << endl;
cout << line << endl;
}
stream1.close();
stream2.close(); return 0;
}
How can i make this code make it so that if it finds the word for example “HELLO” in a line it will save into stream2 that Entire line? The rest of the lines if it doesnt have that word wont save to stream2.
Basically if it finds the word “HELLO” in a line while reading it. It outputs it. If not then skip the line.
1 Answer