Created
May 7, 2015 01:29
-
-
Save OlafSamael/d5607d681a3ea5472dbe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
#include <string> | |
#include <algorithm> | |
using namespace std; | |
void check_banana (string filename){ | |
string line; | |
string banana = "banana"; | |
int count = 0; | |
ifstream myfile; | |
myfile.open ("banana.txt"); | |
if (myfile.good() == true){ | |
while (getline (myfile, line)){ | |
transform(line.begin(),line.end(),line.begin(), ::tolower); | |
if (line.find (banana) != string::npos){ | |
count ++; | |
} | |
} | |
cout << "Number of times that 'banana' appears: " << count << endl; | |
} | |
} | |
int main (){ | |
string name; | |
cout << "Name of the file:" << endl; | |
cin >> name; | |
cout << endl; | |
check_banana (name); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment