You should be comfortable with the content in the modules up to and including the module "Input Output" for this project.html
You must follow the style guidefor all projects.ios
For this project, download the text file weblog.txt
Note: To download this file, right click on the link and select SAVE ASweb
This file is an Apache web log taken from the web server for St. Mary's University. When a visitor goes to their web site, the visitor's browser makes a request to the web server to view a web page, which is a file residing on the server. Each time a page is requested by a browser, the web server records information about that request. This weblog.txt holds the details of some of those requests. See below for a list of fields with an example:apache
This file does not include all possible information that could be collected by a web server. The full description of the apache log file format can be found here: http://httpd.apache.org/docs/2.2/logs.htmlide
For this project, you can use each line of the web log file as one string using the string class' getline function.ui
Minimum Requirements:this
Answerspa
#include<iostream>
#include<sstream>
#include<fstream>
#include<vector>
#include<algorithm>orm
using namespace std;
木其工做室
void readFile(vector<string>& myVector);
void outFile(vector<string>& myVector);
void sortVector(vector<string>& myVector);
int main()
{
vector<string> myVector;
readFile(myVector);
sortVector(myVector);
outFile(myVector);
system("pause");
return 0;
}
void readFile(vector<string>& myVector)
{
string line;
ifstream myfile ("weblog.txt");
if (myfile.is_open())
{
while( getline(myfile, line) )
{
myVector.push_back(line);
}
myfile.close();
cout<<"File Read successfully."<<endl;
}
else
{
cout<<"Error"<<endl;
}
}
void outFile(vector<string>& myVector)
{
//writing to a file
ofstream outFile;
outFile.open("weblogSorted.txt");
for(unsigned int i = 0; i<myVector.size(); i++)
{
outFile<<myVector[i]<<std::endl;
}
outFile.close();
cout<<"Sorted elements written to a file."<<endl;
}
void sortVector(vector<string>& myVector)
{
//sorting vector
std::sort(myVector.begin(), myVector.end());
cout<<"Vector sorted successfully successfully."<<endl;
}
No attachments uploaded.