I have made this program which will give the word with it's frequency on output but I want to make it like it would automatically end program when all words are read in text file Right now it is iterating 100 times no what how many words are in text file
#include <fstream>
#include <iostream>
#include <sstream>
#include <map>
#include <cctype>
usingnamespace std;
string lowerCase( string s )
{
for ( char &c : s ) c = tolower( c );
return s;
}
int main()
{
// ifstream in( "Doc1.txt" );
istringstream in( "Three blind mice\n""Three blind mice\n""See how they run\n""See how they run\n""They all ran after the farmer's wife\n" );
map<string,int> freq;
for ( string word; in >> word; ) freq[lowerCase(word)]++;
for ( auto p : freq ) cout << p.first << ": " << p.second <<'\n';
}
Brother requirement of my program is to use 2d array
Using a string to do the counting ... is utterly bonkers.
A map is a perfectly good "2d array" in this particular problem. Its dimensions are effectively size x 2, whilst you are (attempting to) use an array of dimensions 100 x 2.