Cstring
The Cstring is a memory managed wrapper class for C-style strings (char*):
- Conversions allow passing Cstrings to C string function arguments
- Assignment, comparison, concatenation, and other functions
Cstring is not meant as a full-featured std::string substitute but rather for code that must interact extensively with C string interfaces where a memory managed C string would be useful.
There are a range of Cstring constructors, for example:
Cstring first( "Tom" ); // C string
Cstring initial( 'E' ); // char Cstring street( the_street ); // std::string Cstring essay( 500 ); // Length |
Single characters in an Cstring are indexed starting at 0 using the [] operator as in C strings:
first[0] = 'D'; // Tom -> Dom |
Concatenation is done with the + operator, as in std::string:
Cstring full_name( first + ' ' + last ); |
Zero-length Cstrings are supported but since they have no valid index positions indexing and substring operations cannot be performed on them.
Cstrings can interoperate with C++ std::string in constructors, assignment, comparison, and concatenation.
The Cstring implementation includes a few member for convenience: length, predicates, searching, case-changing, and justification. See the Cstring source to explore the full capabilities.
|