CS 106B Lecture Notes - Lecture 2: Function Prototype, C String Handling, String Literal
Document Summary
Extra office hours with megan @ gate 104, 10am-11am. Most operators and control flow is the same. Need to #include string s = hello ; A string is a possibly empty sequence of characters. Strings in c++ are conceptually similar to java strings. You can concatenate strings using + or += Unlike java, you can compare strings using relational operators string s2 = megan ; if (s2 >s1 && s2 != keith ){ Unlike java, strings are mutable s1. append( piech ) s1. erase(3, 2) C strings (any string literal such as hi there is a c string. String s = hi + there ; (does not compile) N is now memory address of c string. String s = hi + ?"; string s = hi + 41 (produces garbage) String s = hi ; s+=41; (adds ascii value of 41)