19.1 NEW TYPE STRING
Strings are inseparable part of computer programming. We have already learned C-strings. Now, ISO standard C++ has included a new type called string. It is available in namespace std. In fact, it is a template-based container class. We need not worry about how it is implemented internally. The outward interface of this type is very simple and intuitive. Let us study this type in detail.
Normal operations with strings are:
- Declaring and constructing a string.
- Reading a string from console.
- Writing a string to screen.
- Copying one string into another.
- Comparing two strings.
- Other operations.
19.1.1 Declaring and constructing a string
We can declare a string variable simply as:
string str1 ;
This creates a string variable called ...
Get Object Oriented Programming with C++, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.