1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
#include<iostream>
#include<fstream>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<sstream>
using namespace std;
void erasee(string text_m);
void buffer(ifstream in_file_m, string filename_n);
int main()
{
ifstream in_file;
string fileName, words, test, text;
stringstream buffer;
int counter = 0;
cin >> fileName;
in_file.open(fileName.c_str());
if(in_file.fail())
{
return 0;
}
while(!in_file.eof())
{
in_file >> text;
}
in_file.close();
erasee(text);
buffer(in_file, fileName);
size_t pos = 0;
while(true)
{
pos = test.find(text, pos);
if (pos != std::string::npos)
{
counter++;
pos++;
}
else break;
}
cout << text << " " << counter;
return 0;
}
void erasee(string text_m)
{
string text;
text.erase(std::remove(text.begin(), text.end(), '.'), text.end());
text.erase(std::remove(text.begin(), text.end(), ','), text.end());
text.erase(std::remove(text.begin(), text.end(), '!'), text.end());
text.erase(std::remove(text.begin(), text.end(), '?'), text.end());
text.find_last_of(" ");
}
void buffer(ifstream in_file_m, string filename_n)
{
stringstream buffer;
string test, words, fileName;
ifstream in_file;
in_file.open(fileName.c_str());
while(!in_file.eof())
{
buffer << in_file.rdbuf();
test = buffer.str();
getline(in_file, words);
}
in_file.close();
}
|