From the course: Complete Guide to C++ Programming Foundations
Unlock this course with a free trial
Join today to access over 24,800 courses taught by industry experts.
The string class - C++ Tutorial
From the course: Complete Guide to C++ Programming Foundations
The string class
- [Instructor] Now let me show you how the string class from the C++ standard library provides a more flexible and safer way to handle strings when compared to cstrings. Well, C++ provides a class to represent strings as objects with properties and functions. This is the object oriented approach to strings that's embedded in the language. Here we have the same code we created for reporting the winner in a race game using C style strings, which are just a race of characters. I will replace some lines of code in this file to use the string class instead. Let's start by replacing the cstring header with the string header, which contains the definition of the string class. Now, I'll remove the declaration of the length constant because the string class manages the length of its strings automatically. There's no need for you to worry about that. Now let's replace our cstring declarations with std string objects. We'll declare racer 1 and racer 2 as std strings. Now be aware that we can…
Contents
-
-
-
-
-
-
(Locked)
Arrays7m 27s
-
Pointers7m 59s
-
(Locked)
How arrays and pointers are related5m 14s
-
(Locked)
Using objects with pointers10m 56s
-
(Locked)
The vector class5m
-
(Locked)
Using objects with vectors6m 29s
-
(Locked)
References4m 56s
-
(Locked)
C strings11m 16s
-
(Locked)
The string class4m 14s
-
(Locked)
Solution: Vector manipulation2m
-
(Locked)
-
-
-
-
-
-