I'm relatively new to this and need help counting the number of times a user provided word appears in a user provided file
this is what I got:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
ifstream infile;
string str, filename;
int count, num;
count = 0;
num = 0;
cout << "Enter File Name: \n";
cin >> filename;
infile.open(filename.c_str());
if(!infile)
{
cout << "Error...Could not find file!!!\a";
}
cout << "Enter word to look for : \n";
cin >> str;
while () //Need help counting number of times the user
{ //input word shows up in the user provided file...
num++;
}
cout << str << ": " << num << "\n";
while(infile >> str)
{
count++;
}
cout << "Frequency: " << (double)num/count << endl;
return 0;
}