Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream> // ifstream, open, eof, close
- using namespace std;
- int main()
- {
- // step 1
- ifstream data_store;
- string filename;
- cout << "What is the name of the filename?" << endl;
- getline(cin, filename);
- // step 2
- data_store.open(filename.c_str());
- // step 3
- if (!data_store) // If any problem with file
- {
- cout << "Fatal Error: Can not find " << filename << "." << endl;
- return 0;
- }
- string data;
- int num_found = 0;
- while (!data_store.eof()) // While we are not at the end of file
- {
- data_store >> data; // Reading a word from the data store (not the keyboard)
- if (data == "Romeo" || data == "Romeo's" || data == "Romeo." || data == "Romeo?" || data == "Romeo,"
- || data == "Romeo!")
- {
- num_found++;
- }
- cout << data << endl;
- }
- cout << "Found " << num_found << " cases of Romeo" << endl;
- // step 4
- data_store.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement