我一直在尝试将我的程序拆分为头文件和主文件,但无法完全弄清楚头文件将如何与它一起工作。任何试图理解这一点的帮助将不胜感激。
#include <iostream>
#include <fstream>
#include <string>
#include <set>
void comparing(std::ifstream& fileIn, std::ifstream& keywords, std::ofstream& outFile)
{
std::string str;
std::string word;
std::set<std::string> keywordsSet;
int check = 0;
while (keywords >> word) {
keywordsSet.insert(word);
}
while(fileIn >> str){
if(str == "<p>") {
check++;
}
if((check > 1 && str == "<p>") || (check == 1 && str == "</body>"))
{
outFile << "</p>";
check--;
}
if(keywordsSet.find(str) != keywordsSet.end()) {
outFile << "<i>" << str << "</i>" << " ";
}
else{
outFile << str << " ";
}
}
}
int main(int argc, char* argv[])
{
std::ifstream fileIn;
fileIn.open (argv[1]);
std::ifstream keywords;
keywords.open (argv[2]);
std::ofstream outFile;
outFile.open(argv[3]);
comparing(fileIn, keywords, outFile);
fileIn.close();
keywords.close();
outFile.close();
return 0;
}