(20 points) KWIC is an acronym for ”Key Word In Context”. This is the most common format for
concordance indexes in documents. It is also the starting point for most spelling and grammar checkers
in word processors. You will use the classes in the C++ Standard Library to write a program that
creates such an index for text read from the standard input.
Begin by writing a C++ function that has a single argument: a string containing a file name and
returns a reference to a list of stings. Open the file and then read each word in the text file into a
C++ STL list of strings. Return
#include <iostream>
#include <iomanip>
#include <list>
#include <fstream>
#include <string>
using namespace std;
//Function read all string and return it in list STL
list<string> ReadFie(const char* fname)
{
ifstream inp(fname);
if(!inp)
{
cout<<"We can't find file\n";
return list<string>();
}
string line;
list<string>ans;
while (getline(inp, line))
{
cout<<line<<endl;
ans.push_back(line);
}
//Close file handling
inp.close();
return ans;
}
int main()
{
list<string>ls=ReadFie("base.txt");
for(auto it:ls)
cout<<it<<endl;
return 0;
}
Comments
Leave a comment