3
Now you know the basics Really! Congratulations! Really! Congratulations! Dont get stuck with a sterile focus on programming language features Dont get stuck with a sterile focus on programming language features What matters are programs, applications, what good can you do with programming What matters are programs, applications, what good can you do with programming Text processing Text processing Numeric processing Numeric processing Embedded systems programming Embedded systems programming Banking Banking Medical applications Medical applications Scientific visualization Scientific visualization Animation Animation Route planning Route planning Physical design Physical design Stroustrup/PPP - Oct'113

4
Text processing all we know can be represented as text all we know can be represented as text And often is And often is Books, articles Books, articles Transaction logs (email, phone, bank, sales, …) Transaction logs (email, phone, bank, sales, …) Web pages (even the layout instructions) Web pages (even the layout instructions) Tables of figures (numbers) Tables of figures (numbers) Mail Mail Programs Programs Measurements Measurements Historical data Historical data Medical records Medical records … Stroustrup/PPP - Oct'114 Amendment I Congress shall make no law respecting an establishment of religion, or prohibiting the free exercise thereof; or abridging the freedom of speech, or of the press; or the right of the people peaceably to assemble, and to petition the government for a redress of grievances.

9
I/O overview Stroustrup/PPP - Oct'119 istreamostream ifstreamiostreamofstreamostringstreamistringstream fstreamstringstream Stream I/O in >> xRead from in into x according to xs format out << x Write x to out according to xs format in.get(c)Read a character from in into c getline(in,s)Read a line from in into the string s

10
Map overview Associative containers Associative containers,,,,,, map map multimap multimap set set multiset multiset unordered_map unordered_map unordered_multimap unordered_multimap unordered_set unordered_set unordered_multiset unordered_multiset The backbone of text manipulation The backbone of text manipulation Find a word Find a word See if you have already seen a word See if you have already seen a word Find information that correspond to a word Find information that correspond to a word See example in Chapter 23 See example in Chapter 23 Stroustrup/PPP - Oct'1110

13
A problem: Read a ZIP code Problems with simple solution Problems with simple solution Its verbose (4 lines, 8 function calls) Its verbose (4 lines, 8 function calls) We miss (intentionally?) every ZIP code number not separated from its context by whitespace We miss (intentionally?) every ZIP code number not separated from its context by whitespace "TX77845", TX77845-1234, and ATM77845 "TX77845", TX77845-1234, and ATM77845 We miss (intentionally?) every ZIP code number with a space between the letters and the digits We miss (intentionally?) every ZIP code number with a space between the letters and the digits TX 77845 TX 77845 We accept (intentionally?) every ZIP code number with the letters in lower case We accept (intentionally?) every ZIP code number with the letters in lower case tx77845 tx77845 If we decided to look for a postal code in a different format we have to completely rewrite the code If we decided to look for a postal code in a different format we have to completely rewrite the code CB3 0DS, DK-8000 Arhus CB3 0DS, DK-8000 Arhus Stroustrup/PPP - Oct'1113

19
Regular expression syntax Regular expressions have a thorough theoretical foundation based on state machines Regular expressions have a thorough theoretical foundation based on state machines You can mess with the syntax, but not much with the semantics You can mess with the syntax, but not much with the semantics The syntax is terse, cryptic, boring, useful The syntax is terse, cryptic, boring, useful Go learn it Go learn it Examples Examples Xa{2,3}// Xaa Xaaa Xa{2,3}// Xaa Xaaa Xb{2}// Xbb Xb{2}// Xbb Xc{2,}// Xcc Xccc Xcccc Xccccc … Xc{2,}// Xcc Xccc Xcccc Xccccc … \w{2}-\d{4,5}// \w is letter \d is digit \w{2}-\d{4,5}// \w is letter \d is digit (\d*:)?(\d+) // 124:1232321 :123 123 (\d*:)?(\d+) // 124:1232321 :123 123 Subject: (FW:|Re:)?(.*)//. (dot) matches any character Subject: (FW:|Re:)?(.*)//. (dot) matches any character [a-zA-Z] [a-zA-Z_0-9]*// identifier [a-zA-Z] [a-zA-Z_0-9]*// identifier [^aeiouy] // not an English vowel [^aeiouy] // not an English vowel Stroustrup/PPP - Oct'1119

20
Searching vs. matching Searching for a string that matches a regular expression in an (arbitrarily long) stream of data Searching for a string that matches a regular expression in an (arbitrarily long) stream of data regex_search() looks for its pattern as a substring in the stream regex_search() looks for its pattern as a substring in the stream Matching a regular expression against a string (of known size) Matching a regular expression against a string (of known size) regex_match() looks for a complete match of its pattern and the string regex_match() looks for a complete match of its pattern and the string Stroustrup/PPP - Oct'1120