Here are the requirements for a project I am working on.
Write a function that will write only unique ip addresses to a file (just the ip address, not the entire line).
Write a function that will search for an ip address and display all page requests for that ip address.
The ip is pulled from a "weblog.txt" file which has been put into a vector and sorted. I am having trouble with the loop to pull only unique ip addresses from the vector.
[code]
#include<iostream>
#include<vector>
#include<fstream>
#include<string>
#include<algorithm>
First a few comments:
1. Try not to use global variables. Your functions can pass/return variables, so try that instead.
2. An example of the lines in weblog.txt would have been nice. For this discussion, I will assume that each line contains xxx.xx.xxx.xx/folder/page.html
3. If that is the case, use find_first_of function for strings to find the position of "/", and the IP address is the substring up to that position. For the following functions, I assume that you can write a function std::string getIP(std::string) that just returns the IP
Now here is how I would look for unique IP addresses: