Hello there. I need help in coding for visual C++. I am trying to read a
text file. I want to copy only those lines which have the word "Commercials". I also want to trim the line so that I can copy only relavant information. Here is the sample text file (2 lines only):
2006.06.14 00:00:42:18 New Channel Play F:\H\Channel-S_VIDEO\Commercials\Rubicon---1.avi
2006.06.14 00:01:32:15 New Channel Play F:\H\Channel-S_VIDEO\Logos\Channel S ID Com Voice-Logo.avi
At this point, I need to know how to extract lines with the word "Commercial" and write to another file.
Thank you.
Here is my coding:
#include <fstream>
#include <string>
using namespace std;
int main () {
string line;
ifstream myfile ("type2.txt");
if (myfile.is_open())
{
while (! myfile.eof() )
{
cout <<line<<endl;
getline (myfile,line);
line.erase(23,38);
cout << line << endl;
}
myfile.close();
}
else cout << "Unable to open file";
return 0;