Answer to Question #331782 in C++ for att

Question #331782

(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


1
Expert's answer
2022-04-21T07:02:56-0400





#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS