Ch 8. Characters and Strings

5/31/00


Click here to start


Table of Contents

Ch 8. Characters and Strings

Characters and Literals Strings

Character Literals and the cctype Library

String Literals

char * text = "A Literal Text";

The cstring Library

The cstring Library

int strcmp (const unsigned char * p, const unsigned char * q) { while (*p && (*p == *q)) { p++; q++; } return *p - *q;

Constant and Mutable Values

Constant and Mutable Values

Constant and Mutable Values

Constant and Mutable Values

Constant and Mutable Values

The string Data Type

string a;

Table 8.1 Comparison of string functionality in C++ and Java

Example - Split a Line into Words

int main() { string text = "it was the best of times, it was the worst of times."; list<string> words; string separators = " .,!?:"; split(text, separators, words); string smallest = words.front(); string largest = words.front(); list<string>::iterator current; list<string>::iterator stop = words.end(); for (current = words.begin(); current != stop; ++current) { if (*current < smallest) smallest = *current; if (largest < *current) largest = *current; } cout << "smallest word " << smallest << endl; cout << "largest word " << largest << endl; return 0;

Author: Seung Sean Yoo

Email: budd@cs.orst.edu

Home Page: http://www.cs.orst.edu/~budd