Skip to main content

Working with Strings

  • Chapter
  • First Online:
Beginning C++20
  • 3117 Accesses

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:

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 54.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 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. 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. 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. 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

Authors

Rights and permissions

Reprints and permissions

Copyright information

© 2020 Ivor Horton and Peter Van Weert

About this chapter

Check for updates. Verify currency and authenticity via CrossMark

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

Publish with us

Policies and ethics