Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <string>
- using namespace std;
- bool equal(const string& cw, const string& w) {
- char punct[] = {'.',',','?','!'};
- if (cw == w) return true;
- for (int i=0; i < sizeof(punct); ++i)
- if (cw == w + punct[i]) return true;
- return false;
- }
- int main() {
- string word, curword;
- cout << " Введите слово для поиска: ";
- cin >> word;
- ifstream fin("infile.txt");
- if (!fin) { cout << "Ошибка открытия файла." << endl; return 1; }
- int count = 0;
- while (!fin.eof()) {
- fin >> curword;
- if (equal(curword, word)) count++;
- }
- cout << "Количество вхождений слова: " << count << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement