Содержание
- 2. Overview Application domains Strings I/O Maps Regular expressions Stroustrup/PPP - Nov'13
- 3. Now you know the basics Really! Congratulations! Don’t get stuck with a sterile focus on programming
- 4. Text processing “all we know can be represented as text” And often is Books, articles Transaction
- 5. String overview Strings std::string s.size() s1==s2 C-style string (zero-terminated array of char) or strlen(s) strcmp(s1,s2)==0 std::basic_string
- 6. C++11 String Conversion In , for numerical values For example: string s1 = to_string(12.333); // "12.333"
- 7. String conversion We can write a simple to_string() for any type that has a “put to”
- 8. C++11 String Conversion Part of , for numerical destinations For example: string s1 = "-17"; int
- 9. String conversion We can write a simple from_string() for any type that has an “get from”
- 10. General stream conversion template Target to(Source arg) { std::stringstream ss; Target result; if (!(ss || !(ss
- 11. I/O overview Stroustrup/PPP - Nov'13
- 12. Map overview Associative containers , , , map multimap set multiset unordered_map unordered_multimap unordered_set unordered_multiset The
- 13. Map overview Stroustrup/PPP - Nov'13
- 14. A problem: Read a ZIP code U.S. state abbreviation and ZIP code two letters followed by
- 15. A problem: Read a ZIP code Problems with simple solution It’s verbose (4 lines, 8 function
- 16. TX77845-1234 1st try: wwddddd 2nd (remember -12324): wwddddd-dddd What’s “special”? 3rd: \w\w\d\d\d\d\d-\d\d\d\d 4th (make counts explicit):
- 17. #include #include #include using namespace std; int main() { ifstream in("file.txt"); // input file if (!in)
- 18. int lineno = 0; string line; // input buffer while (getline(in,line)) { ++lineno; smatch matches; //
- 19. Results Input: address TX77845 ffff tx 77843 asasasaa ggg TX3456-23456 howdy zzz TX23456-3456sss ggg TX33456-1234 cvzcv
- 20. Regular expression syntax Regular expressions have a thorough theoretical foundation based on state machines You can
- 21. Searching vs. matching Searching for a string that matches a regular expression in an (arbitrarily long)
- 22. Table grabbed from the web KLASSE ANTAL DRENGE ANTAL PIGER ELEVER IALT 0A 12 11 23
- 23. Describe rows Header line Regular expression: ^[\w ]+( [\w ]+)*$ As string literal: "^[\\w ]+( [\\w
- 24. Simple layout check int main() { ifstream in("table.txt"); // input file if (!in) error("no input file\n");
- 25. Simple layout check int main() { // … open files, define patterns … if (getline(in,line)) {
- 26. Validate table int boys = 0; // column totals int girls = 0; while (getline(in,line)) {
- 28. Скачать презентацию