You are on page 1of 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