파일로로드하고 각 행을 특정 단어 배열과 비교하고 해당 행을 비교하는 작은 프로그램을 작성하려고합니다. 그 단어들 중 하나를 가지고 있다면 그 줄을 파일에 "인쇄"하고 싶습니다.문자열을 특정 단어와 비교하고 일치하는 것이 발견되면 전체 문자열을 인쇄하십시오.
내 현재 코드는 다음과 같습니다
int main()
{
string wordsToFind[13] =
{"MS SQL", "MySQL", "Virus", "spoof", "VNC", "Terminal", "imesh", "squid",
"SSH", "tivo", "udp idk", "Web access request dropped", "bounce"};
string firewallLogString = "";
ifstream firewallLog("C:\\firewalllogreview\\logfile.txt");
ofstream condensedFirewallLog("C:\\firewalllogreview\\firewallLog.txt");
if(firewallLog.fail())
{
cout << "The file does not exist. Please put the file at C:\\firewalllogreview and run this program again." << endl;
system("PAUSE");
return 0;
}
while(!firewallLog.eof())
{
getline(firewallLog, firewallLogString);
for(int i = 0; i < 13; i++)
{
if(firewallLogString == wordsToFind[i])
{
firewallLogString = firewallLogString + '\n';
condensedFirewallLog << firewallLogString;
cout << firewallLogString;
}
}
}
condensedFirewallLog.close();
firewallLog.close();
}
나는 프로그램이 문자열을 비교하며, 일치하는 경우에만 대신 문자열의 특정 단어를 출력합니다 실행
. 어떤 도움이라도 대단히 감사 할 것입니다.
이것은 정확하게 내가해야 할 일입니다. 감사합니다! – Huntertusk