WSQ 11- Go bananas.


Here is my code: doggy

#include <algorithm>

#include <iostream>

#include <fstream>

#include <string>

using namespace std;


int count (string ban){

int bananaCount;

ifstream infile;

int pos;“banana.txt”);


string line;


if (infile.is_open())



transform(line.begin(), line.end(), line.begin(), ::tolower);

pos = line.find(ban);

while(pos != -1){

cout << “OMG I found a banana at position: ” << pos << endl;


pos = line.find(ban,pos+1);




return bananaCount;

infile.close( );

int main(){

string ban=”banana”;

cout<<“Number of bananas: “<<count(ban) <<endl;
return 0;


This program was pretty easy cause I already had a program to open files. All I had to do was counting the number of bananas inside a file. The new part about this was that I used a new kind of function inside the algorithm library, it was “transform”. Here I used a lot of mastery topics.


Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de

Estás comentando usando tu cuenta de Cerrar sesión /  Cambiar )

Google photo

Estás comentando usando tu cuenta de Google. Cerrar sesión /  Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión /  Cambiar )

Conectando a %s