Skip to content

Latest commit

 

History

History
31 lines (29 loc) · 673 Bytes

File metadata and controls

31 lines (29 loc) · 673 Bytes
#include <iostream>
using std::cin; using std::cout; using std::endl; using std::cerr;
#include <fstream>
using std::fstream;
#include <string>
using std::string;
#include <list>
using std::list;
#include <algorithm>
using std::count;

int main() {
    cout << "Please type the filename: ";
    string fn, tmp;
    list<string> ls;
    getline(cin, fn);
    fstream input(fn);
    if (input.is_open()){
        while (input >> tmp)
            ls.push_front(tmp);
    } else {
        cerr << "Failed to open file" << endl;
        return EXIT_FAILURE;
    }
    string s = "is";
    cout << count(ls.cbegin(), ls.cend(), s) << endl;
    return EXIT_SUCCESS;
}