Hello everyone!
I am in need of some help with a homework assignment. It's basically creating a file indexer using C++.
I have 2 separate files that I need to read in: one is a text document and the other is a Skip words key. I am incredibly confused about how to approach this.
I know how to read both of them in and place them into separate containers (I plan on using vectors) but I just don't know how to combine them so that the Skip words text that line up with the document text won't be displayed (do I combine them into a map?).
I then need to display words that weren't in the skipWords doc in alphabetical order (I plan on using a vector and just sorting them) and output each location they appear.
Here is the doc file:
The quick brown fox
jumped over the lazy blue
fox. I can not believe I wrote such
a common phrase.
<newpage>
Where or where are you tonight?
Why did you leave me here all
alone?
<newpage>
I searched the world over
and thought I found true love.
Here is the skipWords file:
why
are
did
here
i
not
me
a
or
you
such
where
and
the
This is the code I have so far:
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include "Indexer.h"
typedef vector<string> docText;
typedef vector<string> skipWords;
using namespace std;
void insertDocVector()
{
string fileName;
docText docText;
cout << "Please enter a document file name: ";
cin >> fileName;
ifstream inFile(fileName.c_str(), ios::in);
if (!inFile)
{
cerr << "Error opening file '" << fileName << '\'' << endl;
system("pause");
exit(EXIT_FAILURE);
}
copy(istream_iterator<string>(inFile),
istream_iterator<string>(),
back_inserter(docText));
}
void insertSkipVector()
{
skipWords toSkip;
string fileName;
cout << "Please enter a skip-words file name: ";
cin >> fileName;
ifstream inFile(fileName.c_str(), ios::in);
if (!inFile)
{
cerr << "Error opening file '" << fileName << '\'' << endl;
system("pause");
exit(EXIT_FAILURE);
}
copy(istream_iterator<string>(inFile),
istream_iterator<string>(),
back_inserter(toSkip));
}
int main()
{
cout << "\t\t\t\t***The Indexer***\n\n";
insertDocVector();
cout << endl;
insertSkipVector();
cout << endl;
system("pause");
return 0;
}
The Indexer header is just going to announce my prototypes and that's it. I don't intend on using any constructors. All I have is just reading the files in and placing them into separate vectors.
Can someone offer a stepping stone? I'm good at figuring it out if people just ask me the right questions :) I'm not asking for code, just guidance. Thank you so much in advance!