25% Extra Free

My work, my life

My Photo
Name:
Location: United Kingdom

half-man, half-geek

Friday, February 02, 2007

I am a BANANA

Programming examples are rarely exciting or even interesting. They usually consist of various foo's and bar's being created and destroyed. That is why I like this from www.cppreference.com (link)

For example, the following code uses the find() function to determine how many times a user entered a certain word:

  map stringCounts;
string str;

while( cin >> str ) stringCounts[str]++;

map::iterator iter = stringCounts.find("spoon");
if( iter != stringCounts.end() ) {
cout << "You typed '" <<>first << "' " <<>second << " time(s)" <<>

When run with this input:

my spoon is too big.  my spoon is TOO big!  my SPOON is
TOO big! I am a BANANA!

...the above code produces this output:

You typed 'spoon' 2 time(s)
Indeed ...
PS be careful out there!

0 Comments:

Post a Comment

<< Home