Skip to content

Instantly share code, notes, and snippets.

@OlafSamael
Created May 7, 2015 01:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OlafSamael/d5607d681a3ea5472dbe to your computer and use it in GitHub Desktop.
Save OlafSamael/d5607d681a3ea5472dbe to your computer and use it in GitHub Desktop.
#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