Abstract
This chapter is about handling textual data much more effectively and safely than the mechanism provided by a C-style string stored in an array of char elements:
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 1.
Provided proverb itself is not of type const std::string. If proverb is const, data() results in a const char* pointer as well. We refer you to Chapter 11 for more details on the relation between const objects and const member functions. Prior to C++17, data() always resulted in a const char* pointer, even for non-const strings, just like c_str().
- 2.
The character with code 6 is generally a non-printable character—more specifically the transition control character ‘ACK’ (acknowledge). To better visualize what happens you could therefore for instance output the result of std::string ounce{111, ‘z’};, which is generally the string ”oz”.
- 3.
Or, for our younger readers who are no longer familiar with archaic paper relics such as dictionaries and phone books: in the same manner as your contacts are ordered on your smart phone.
- 4.
Well, almost always, actually, if we’re being pedantic. Every string begins and ends with the empty string, even empty strings.
Author information
Authors and Affiliations
Rights and permissions
Copyright information
© 2020 Ivor Horton and Peter Van Weert
About this chapter
Cite this chapter
Horton, I., Van Weert, P. (2020). Working with Strings. In: Beginning C++20. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4842-5884-2_7
Download citation
DOI: https://doi.org/10.1007/978-1-4842-5884-2_7
Published:
Publisher Name: Apress, Berkeley, CA
Print ISBN: 978-1-4842-5883-5
Online ISBN: 978-1-4842-5884-2
eBook Packages: Professional and Applied ComputingApress Access BooksProfessional and Applied Computing (R0)