Course Content
Introduction to C++
String
In addition to numbers (int
, double
etc.) and symbols(char
) in variables, you can also store text. For this, you need to:
- Connect the
string
module; - Get the
string
object from thenamespace std
; - Declare a variable of type
string
.
main.cpp
\n
– is the new line symbol (same as endl
, but a symbol).
Strings variables can also contain numbers (as text):
main.cpp
If you try to add two string variables, you get a concatenation:
main.cpp
The same thing will happen with numbers – they will not be added algebraically.
To find out the length of a string, we can use the standard length()
function:
main.cpp
Section 2.
Chapter 4