From the course: C++ Templates and the STL

Unlock this course with a free trial

Join today to access over 22,400 courses taught by industry experts.

Transforming strings

Transforming strings - C++ Tutorial

From the course: C++ Templates and the STL

Transforming strings

- [Narrator] Transforming strings is a bit of a special case, because strings are not obviously containers. The string class however, is a class with an interface that's compatible with other SDL container classes. So here I have a working copy of string-transform.cpp. From chapter four of the exercise files. Here we have two SDL strings, s1, and s2. S1 is a normal string, and s2 is a string of the same size as s1, that's been filled with dots, with periods. And I could actually display s2 here as well. And then there's a transform function. Which as its fourth argument, as its transforming operator, uses this toupper function. You'll notice these scope resolution operator. This simply distinguishes between the function and a colon macro, in the standard library so, when I build and run this, you see that our transformation is starting at the beginning, and ending at the end of string 1, and depositing the results in string 2. String 2 starts out as a string full of periods, and then…

Contents