7 With strings attached - working with string literals
This chapter covers
- Understanding the concept of strings and how they differ from character arrays
- Declaring and initializing string literals, working with std::string
- Using std::string methods to find, insert, replace, remove elements from a string and more
- Trimming and formatting strings
- Using string comparison using three-way comparison and other methods
- Using wstring multi-lingual input
In this chapter, you will expand your skillset by learning about strings, a commonly used data type in C++ that represents a sequence of characters. You will understand what strings are and when they are used (spoiler: in almost any program). You will also learn about various std::string methods for manipulating, searching, inserting, replacing, and removing elements from strings. We will dive deep into string trimming, which is a way to get rid of leading and trailing whitespace characters from a string. We will also explore in greater detail how to use the three-way comparison operator (also known as the spaceship operator) to compare strings, as you learned about in Chapter 3.