Lecture overview -- Keyboard shortcut: 'u'  Previous page: C-style strings -- Keyboard shortcut: 'p'  Next page: Strings - examples -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Help page about these notes  Alphabetic index  Course home  Lecture 2 - Page 13 : 42
Notes about C++
Basic facilities
C++ style strings

It is recommended to use type string instead of the low-level char* or char[]

  • The C++ Programming Language: Page 48-49, 579
 

  • Type string in C++:

    • string is alias for a basic_string parameterized by char:

      • typedef basic_string<char> string

    • Strings obey value semantics

      • Copied in and out of functions

    • Characters in strings can be accessed in checked mode and unchecked mode:

      • Checked mode: s.at(i)

      • Unchecked mode: s[i]

    • A string is mutable

    • Strings can be copy constructed based on a C-style string

      • string s("Peter");     or     string t = "Peter";

    • The basic_string class supports a large number of string operations