Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <sstream>
- #include <fstream>
- using namespace std;
- int Str_check(string Stroka, string Need) {
- string word;
- stringstream x;
- x << Stroka;
- int i = 0;
- while (x >> word) {
- if (word == Need) {
- i++;
- }
- }
- return i;
- }
- int main() {
- setlocale(0, "rus");
- int i = 0;
- fstream f("file.txt");
- string need, stroka;
- char symbol;
- bool s = false;
- cout << "Введите символ/слово: \n -> ";
- cin >> need;
- if (need.length() == 1) {
- symbol = need[0];
- s = true;
- }
- if (s) {
- char ch;
- while (!f.eof()) {
- ch = f.get();
- if (ch == symbol)
- i++;
- }
- }
- else {
- while (1) {
- getline(f, stroka);
- i = i + Str_check(stroka, need);
- if (f.eof())
- break;
- }
- }
- f.close();
- cout << i << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment