[ create a new paste ] login | about

Link: http://codepad.org/NdA5wifk    [ raw code | output | fork ]

C++, pasted on Jan 14:
#include <string>
#include <iostream>

using namespace std;

bool containsStr(const string& sourceStr, const string& searchStr);

int main() {

  string source_str = "finger";
  string search_str = "finger";
  bool found_finger = containsStr(source_str, search_str);
  if (found_finger) 
      cout<< "We found your finger. And now we will eat it..." <<endl;
  else
      cout<< "Your finger is disgusting. I'm not going to eat it." <<endl;
  
  source_str = "Eat your finger";
  found_finger = containsStr(source_str, search_str);
  if (found_finger)
      cout<< "I just ate my finger!" <<endl;
  else 
      cout<< "Ow! I missed my finger, and ate my whole hand instead!";

  return 0;

}

bool containsStr(const string& sourceStr, const string& searchStr) {

    size_t pos = sourceStr.find(searchStr);
    if (pos == string::npos)
        return false;
    else
        return true;

}


Output:
1
2
We found your finger. And now we will eat it...
I just ate my finger!


Create a new paste based on this one


Comments: