Text Processing
C++ handles text by using std::string and std::string_view utilities.
We'll cover the following
With strings and regular expressions, C++ has two powerful libraries to process text.
String
std::string possesses a rich collection of methods to analyze and modify its text. Because it has a lot in common with an std::vector
of characters, the algorithms of the STL can be used for std::string
. std::string
is the successor of the C string but a lot easier and safer to use. C++ strings manage their memory themselves.
String View
In contrast to a std::string
a std::string_view is quite cheap to copy. A std::string_view
is a non-owning reference to a std::string
.
Regular Expression
Regular expression is a language for describing text patterns. You can use regular expressions to determine whether a text pattern is present once or more times in a particular text. But that’s not all. Regular expressions can be used to replace the content of the matched patterns with a text.
In the next lesson, we will talk about input and output in the C++ Standard Libarary.
Get hands-on with 1400+ tech skills courses.