0% found this document useful (0 votes)
53 views9 pages

String

The document discusses the C++ string class, which provides a data type for storing and manipulating strings. It describes how the string class allows programmers to create string variables, unlike the char data type which can only store one character. It also shows how to include the string header, define string objects, assign string literals, and output string values using cout. Examples are provided to demonstrate simple string programs and displaying string information over multiple lines.

Uploaded by

MA Gamer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views9 pages

String

The document discusses the C++ string class, which provides a data type for storing and manipulating strings. It describes how the string class allows programmers to create string variables, unlike the char data type which can only store one character. It also shows how to include the string header, define string objects, assign string literals, and output string values using cout. Examples are provided to demonstrate simple string programs and displaying string information over multiple lines.

Uploaded by

MA Gamer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

string

Presentation By :
Azam Tariq & Numan Amin
Roll No. IT-146 & IT-148 (G2)
The C++ string Class
• The standard C++ provides a special data type for storing and working
with strings.
• As we know char data type can store only one character in its memory
location.
• Another data type is needed for variable to hold an entire string.
• Although C++ does not provides have a built-in data type able to do
this, standard C++ provides something called the string class that allows
the programmer to create a string type variable.
Using the string class
• The first step in using the string class is to #include the <string>
header file. This accomplished with the following preprocessor directive:
• #include <string>
• The next step is to define a string type variable, called string object.
• string countryName; OR string movieTitle;
• You can assign a string literal to countryName / movieTitle with the
assignment operator.
Using the string class
• countryName = “Pakistan”; OR movieTitle = “Wheel of Fury”;
• You can use cout object to display the value of the countryName /
movieName object as shown below :
• cout << “ The name of my country is : ”<<countryName<<endl;
• OR
• cout << “ The name of my favourite is : ”<<movieName<<endl;
Simple Example Program
• Program Output
Another Example
• Program Output
Write a program that displays the following Pieces of information on separate line:
Your Name , Your Address with city, state , Your Phone number, Your course major.

• Output
Write a program that display your first name on 1st line , your last name on 2nd line
and Full name on the 3rd line using String

Output
Write a program using string type array and display the array .

Output

You might also like