i would love to dig into your code but i just don't have enough strength today..
sorry for not much effort, i'll try to redeem myself at the next occasion
try this out......maybe it can suite you...
Code:
#include <fstream>
#include <iostream>
#include <deque>
#include <string>
#include <cstdlib>
#include <algorithm>
using namespace std;
typedef unsigned short USHORT;
void main()
{
deque<string> text;
string tempStr[100];
ifstream fin("c:\\My Documents\\prose.txt");
ofstream fout("c:\\My Documents\\together.txt");
if(!fin.is_open() || !fout.is_open()){
cerr << "\n\aError: Unable to open prose.txt for input.";
exit(EXIT_FAILURE);
}
else{
// Enter ad write records to the file and deque
USHORT i = 0;
while(i < 100)
{
getline(fin,tempStr[i], char(32));
tempStr[i].resize(4);
for (int j=0;j<tempStr[i].size();j++)
{
tempStr[i][j] = tolower(tempStr[i][j]);
}
text.push_front(tempStr[i]);
i++;
} // End of while(i < 25)...
} // End of else...
deque<string>::iterator itr;
sort(text.begin(),text.end());
// Count the number of times a given word appears
// in the deque of string objects.
itr = text.begin();
cout << endl;
while(itr < text.end())
{
cout << "The word --- " << *itr << " --- appears "
<< count(text.begin(),text.end(),*itr)
<< " times. " << endl;
fout << "The word --- " << *itr << " --- appears "
<< count(text.begin(), text.end(), *itr)
<< " times. " << endl;
itr++;
}
// Display the contents of the deque
itr = text.begin();
while(itr < text.end()) cout << endl << *itr++;
int yu;
cin >> yu;
}
hope this helps...
matheo917