Strings, Pointers and Dynamic Arrays

Strings Pointers - Lecture 5 Strings Pointers and Dynamic Arrays CS 256 Fall 2008 C-String#include Placed in the global namespace not in

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
Lecture 5: Strings, Pointers, and Dynamic Arrays CS 256 – Fall 2008
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
C-String #include <cstring> Placed in the global namespace, not in std namespace no “using namespace std;” needed An array of characters Ends with the null character, ‘\0’ usage char Array_name [Max_size + 1]; char s[10] = “hello”; s = “hello”; //not allowed Use for-loop to process strings like arrays
Background image of page 2
C-String predefined functions A list of predefined c-string functions strcpy(s,t); strcat(s,t); strlen(s) strcmp(s,t) //0 equal, <0 less than, >0 greater than
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Manipulate Characters #include <cctype> A list of functions toupper(ch) tolower(ch) isupper(ch) islower(ch) isalpha(ch) isdigit(ch) Dealing with input/output cin.get(ch); cout << ch; cin.getline(s, len);
Background image of page 4
The Standard Class string To use class string #include <string> using namespace std; string s; string first(“Joe”), last(“The Plumber”); s = first + “ “ + last; cout << s; cin >> s; //what will be s if a user types in Joe The Plumber
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Constructors string str; //default constructor string str(“string”); string str(aString); //take a string object Element access str[i] str.at(i) str.substr(position, length) Assignment/Modifiers s1 = s2;
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/18/2008 for the course CS 256 taught by Professor Dr. yang during the Fall '08 term at Cal Poly Pomona.

Page1 / 19

Strings Pointers - Lecture 5 Strings Pointers and Dynamic Arrays CS 256 Fall 2008 C-String#include Placed in the global namespace not in

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online