I am very grateful to anyone who has time to grade and teach me code standards and ideas.
Requirements:
There are more than 600 HTM files in the Directory D: \ Wamp \ www \ om \ products of Gavin. Now you need to <title> ..... </title> extract to a text file. The text file is divided into two columns. The first column is the absolute path of the file, and the second column is the corresponding <title> ..... </title>, separated by semicolons.
It is known that a filelist.txt file under D: \ Wamp \ www \ om \ products stores all files in the current folder.
Solution: Write a file name using cve-tain.txt, read a file name from filelist.txt, open the file, and extract <title> ..... </title>, the absolute path of the file and <title> ..... </title> write to D: \ Wamp \ www \ om \ products \ mapfile.txt.
The source code is as follows:
// Extradocelem. cpp: defines the entry point of the console application. // # Include "stdafx. H "# include <iostream> # include <fstream> # include <string> # include <windows. h> # include <assert. h> using namespace STD; // search for characters in a file and return the string getstrfromfile (string & filename, string & Str) {string strline; ifstream fin (filename. c_str (); If (! Fin) {cout <"error opening the file" <FILENAME <"for input" <Endl; exit (-1) ;}string: size_type err; while (Getline (FIN, strline) {// cout <strline. c_str () <Endl; err = strline. find (STR); If (ERR = string: NPOs) {// cout <"No title in this file" <Endl ;} else {// cout <strline. c_str () <Endl; // cout <err <Endl; break;} fin. close (); Return strline;} int _ tmain (INT argc, _ tchar * argv []) {string filelist = "d :\\ Wamp \ www \ om \ Products \ filelist.txt "; // string mapfilename =" D: \ Wamp \ www \ om \ products \ mapfile.txt "; // string strdir, the absolute path of the file to store the ing; // string strpath = "D: \ Wamp \ www \ om \ products \\"; string strfind = "<title>"; string strtitle; // 1. each time a row is read to a string ifstream fin (filelist. c_str (); If (! Fin) {cout <"error opening the file" <filelist <"for input" <Endl; exit (-1);} ofstream out_file (mapfilename. c_str (), IOS: APP); While (Getline (FIN, strdir) {strdir = strpath + strdir; strtitle = getstrfromfile (strdir, strfind); cout <strdir. c_str () <Endl; out_file <strdir; out_file <";"; out_file <strtitle; out_file <"\ n";} out_file.close (); Fin. close (); Return 0 ;}