Created
November 5, 2012 08:00
-
-
Save itsjohncs/4015915 to your computer and use it in GitHub Desktop.
Classroom Session 6 - Johnnie Appleseed
This file contains hidden or 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> | |
using namespace std; | |
int main() { | |
string name = "Johnnie Appleseed's Amazing Fruit Stand!"; | |
// What does each of these print out? | |
cout << name.find("Johnnie") << endl; | |
cout << name.find("s") << endl; | |
cout << name.find("Apple") << endl; | |
cout << name.find("x") << endl; | |
if (name.find("x") == -1) { | |
cout << "Where oh where has my x gone?" << endl; | |
} else { | |
cout << "I found an x!" << endl; | |
} | |
return 0; | |
} |
This file contains hidden or 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> | |
using namespace std; | |
int main() { | |
string name = "Johnnie Appleseed's Amazing Fruit Stand!"; | |
// What does each of these print out? | |
cout << name.substr(2) << endl; | |
cout << name.substr(4, 6) << endl; | |
cout << name.substr(5, 2) << endl; | |
cout << name.substr(name.size() - 1) << endl; | |
return 0; | |
} |
This file contains hidden or 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> | |
using namespace std; | |
int main() { | |
string name = "Johnnie Appleseed's Amazing Fruit Stand!"; | |
// What does each of these print out? | |
cout << name.substr(name.find("Appleseed's")) << endl; | |
cout << name.substr(name.find("Amazing"), name.find("Fruit")) << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment