#include <iostream>
#include <map>
#include <sstream>
#include <fstream>
int main() {
//this map maps each word in the file to their respective count
std::map<std::string, int> stringCount;
std::string word, line;
int count = 0;//this count the total number of words
std::ifstream inputFile("log.txt");
if(inputFile)
{
while(std::getline(inputFile, line))//go line by line
{
std::istringstream ss(line);
//increment the count
stringCount[line]++;
}
}
else
{
std::cout<<"File cannot be opened"<<std::endl;
}
inputFile.close();
std::cout<<"Total number of unique ip's are:"<<stringCount.size()<<std::endl;
//lets create a output file and write into it the unique ips
std::ofstream outputFile("code.txt");
for(std::pair<std::string, int> pairElement: stringCount)
{
std::cout<<pairElement.first<<" => "<<pairElement.second<<" times "<<std::endl;
outputFile<<pairElement.first<<" => "<<pairElement.second<<" times \n";
}
outputFile.close();
return 0;
}
192.168.4.163
192.168.4.163
192.168.4.163
192.168.6.163
192.168.6.163