In: Computer Science
For C++
Write a program that opens a specified text file then displays a list of all the unique words found in the file. Hint: Store each word as an element of a set.
//C++ program
#include <bits/stdc++.h>
using namespace std;
int main()
{
ifstream in;
string word, t, q, filename;
set<string>unique;
filename = "input.txt";
in.open(filename.c_str());
while (in >> word)
{
unique.insert( word );
}
set <string> :: iterator itr;
cout << "\nThe Unique Words in file are : \n";
for (itr = unique.begin(); itr != unique.end(); ++itr)
{
cout << *itr<<"\n";
}
cout << endl;
return 0;
}
//input.txt
//sample output