csc201 2010 08 30 Notes

Posted in csc201 by bnmng on 2010 08/30

Next time we meet there will be a homework given.

This week reading homework: Chapter 5

Tonight in class: String ops in Chapter 3; Extraction Operator in Chapter 4; Get; Ignore; File IO

Additional String Operations

sizeof indicates the amount of memory in a variable.
s1 was empty, s2 contained “antidisistablismentarianism”
Thant’s because each string has a pointer and an integer. Regardless of the string that was stored in it.

Note about strings and char’s. A one character string is different from a single char. A one character string is still an array, and includes a character followed by a end of string character.

Strings have corresponding functions. For instance if you have string s1, you can find the length of that string with s1.length. Not to be confused with the sizeof function, the lenght function tells you how many characters are in the string. Note that the the characters in the string are numbered from 0 to 1 less than the length, so a 13 character string will have characters numbered from 0 to 12.

Other string functions. find, as in s1.find. example: s1=”microcomputer” cout << s1.find ("com") finds "com" and returns the position.

String Functions:
length, size, substring (yields another string)

int n;
char ch;
cin >> n; //a cin, followed by the << operator, can only be followed by a variable.

char ch1, ch2, ch3;
cin >> ch1 >> ch2 >> ch3 ;
// input x y z puts ‘x’ in ch1, ‘y’ in ch2, etc.. What if we wanted it to read the whitespace?
you can chain inputs like this: cin.get(ch1).get(ch2).get(ch3).

by convention, put is used with get,

example: ignore
cin >> n;

** note to self: need to read on cin.get, cin.ignore and cin.put ***

string name, s1;
cin >> name;
// in this example, we want John Henry. If we type ” John Henry ” (typing w/o the quotes), only “John” will be put into the string.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: