tailieunhanh - Chapter 9 String

So c-string parameter is array parameter C-strings passed to functions can be changed by receiving function! Like all arrays, typical to send size as well Function "could" also use "\0" to find end, So size not necessary if function won’t change c-string parameter | Chapter 9 Strings Learning Objectives An Array Type for Strings C-Strings Character Manipulation Tools Character I/O get, put member functions putback, peek, ignore Standard Class string String processing Introduction Two string types: C-strings Array with base type char End of string marked with null, "\0" "Older" method inherited from C String class Uses templates C-Strings Array with base type char One character per indexed variable One extra character: "\0" Called "null character" End marker We’ve used c-strings Literal "Hello" stored as c-string C-String Variable Array of characters: char s[10]; Declares a c-string variable to hold up to 9 characters + one null character Typically "partially-filled" array Declare large enough to hold max-size string Indicate end with null Only difference from standard array: Must contain null character C-String Storage A standard array: char s[10]; If s contains string "Hi Mom", stored as: Display, page 370 C-String Initialization Can . | Chapter 9 Strings Learning Objectives An Array Type for Strings C-Strings Character Manipulation Tools Character I/O get, put member functions putback, peek, ignore Standard Class string String processing Introduction Two string types: C-strings Array with base type char End of string marked with null, "\0" "Older" method inherited from C String class Uses templates C-Strings Array with base type char One character per indexed variable One extra character: "\0" Called "null character" End marker We’ve used c-strings Literal "Hello" stored as c-string C-String Variable Array of characters: char s[10]; Declares a c-string variable to hold up to 9 characters + one null character Typically "partially-filled" array Declare large enough to hold max-size string Indicate end with null Only difference from standard array: Must contain null character C-String Storage A standard array: char s[10]; If s contains string "Hi Mom", stored as: Display, page 370 C-String Initialization Can initialize c-string: char myMessage[20] = "Hi there."; Needn’t fill entire array Initialization places "\0" at end Can omit array-size: char shortString[] = "abc"; Automatically makes size one more than length of quoted string NOT same as: char shortString[] = {"a", "b", "c"}; C-String Indexes A c-string IS an array Can access indexed variables of: char ourString[5] = "Hi"; ourString[0] is "H" ourString[1] is "i" ourString[2] is "\0" ourString[3] is unknown ourString[4] is unknown C-String Index Manipulation Can manipulate indexed variables char happyString[7] = "DoBeDo"; happyString[6] = "Z"; Be careful! Here, "\0" (null) was overwritten by a "Z"! If null overwritten, c-string no longer "acts" like c-string! Unpredictable results! Library Declaring c-strings Requires no C++ library Built into standard C++ Manipulations Require library Typically included when using c-strings Normally want to do "fun" things with them = and == with C-strings C-strings not like other variables Cannot .

crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.