SlideShare a Scribd company logo
STRINGS IN C++
CREATED BY:
________________
Instructor:
_________________
_
WELCOM
E
WHAT IS STRING
‱ Like int, double, char, and bool, “String” is a datatype.
‱ Strings are used for storing text (names, sentences, phrases, etc).
‱ For example:
string name = “Pakistan”;
HOW STRING IS USED
A string contains a collection of characters, surrounded by double quotes
Example:
string greeting = "Hello";
USING STRING
‱ To use string, you must include <string> header file in the code
‱ Example
// Include the string library
#include <string>
// Create a string variable
string greeting = "Hello";
SOME STRING EXAMPLES
‱ String firstName = “John”;
‱ String lastName = “Doe”;
// Combining two strings in c++:
‱ String fullName = firstName + lastName;
GET STRING FROM USER
#include <iostream>
#include <string>
using namespace std;
int main() {
string fullName;
cout << "Type your full name: ";
getline (cin, fullName);
cout << "Your name is: " << fullName;
return 0;
}
C++ STRING LENGTH
To check how many characters are stored in a string, we use length() function of string.
Example:
string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
cout << "The length of the txt string is: " << alphabet.length();
//OUTPUT of code:
//The length of the txt string is: 26
THANK YOU
Created by: ___________
Instructor: _________________

More Related Content

PPTX
Mongo db
PPT
Topic 21
PDF
Unit3 browsing the filesystem
ODP
Database2
PDF
Java Week4(A) Notepad
PPT
Filing system in PHP
PPTX
Dspace configuration on XMLUI DSpace
PPT
PHP - Introduction to File Handling with PHP
Mongo db
Topic 21
Unit3 browsing the filesystem
Database2
Java Week4(A) Notepad
Filing system in PHP
Dspace configuration on XMLUI DSpace
PHP - Introduction to File Handling with PHP

What's hot (12)

PPTX
CodeIgniter Helper Functions
PDF
Media wiki
PPT
Green stone
PPTX
Domain name system
PPTX
Files and Folders in Windows 7
PPTX
Presentation about graph database
PPTX
Files in php
PDF
Copy method
PDF
Bettereditors
PPT
Files and Directories in PHP
PPTX
File Handling
CodeIgniter Helper Functions
Media wiki
Green stone
Domain name system
Files and Folders in Windows 7
Presentation about graph database
Files in php
Copy method
Bettereditors
Files and Directories in PHP
File Handling
Ad

Similar to Strings in c plus plus (20)

PPTX
ppt8-string-1.pptx
PPTX
C++ Numbers and Strings.pptx
PPTX
lecture-5 string.pptx
PDF
05 c++-strings
PPTX
String in programming language in c or c++
PPTX
3 (3)Arrays and Strings for 11,12,college.pptx
PPTX
Cs1123 9 strings
PPTX
C++ string
PDF
Strings1
PPTX
The string class
PPT
lecture5.ppt
PPTX
Manipulation strings in c++
PDF
Strinng Classes in c++
PDF
String class and function for b.tech iii year students
PDF
C string _updated_Somesh_SSTC_ Bhilai_CG
PPT
lecture 5 string in c++ explaination and example.ppt
PPT
Strings
PDF
Chapter 3 - Characters and Strings - Student.pdf
DOCX
Programming in c plus plus4
PPT
Computer Programming- Lecture 6
ppt8-string-1.pptx
C++ Numbers and Strings.pptx
lecture-5 string.pptx
05 c++-strings
String in programming language in c or c++
3 (3)Arrays and Strings for 11,12,college.pptx
Cs1123 9 strings
C++ string
Strings1
The string class
lecture5.ppt
Manipulation strings in c++
Strinng Classes in c++
String class and function for b.tech iii year students
C string _updated_Somesh_SSTC_ Bhilai_CG
lecture 5 string in c++ explaination and example.ppt
Strings
Chapter 3 - Characters and Strings - Student.pdf
Programming in c plus plus4
Computer Programming- Lecture 6
Ad

Recently uploaded (20)

PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
medical staffing services at VALiNTRY
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
 
PPTX
L1 - Introduction to python Backend.pptx
PPTX
CHAPTER 2 - PM Management and IT Context
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Digital Strategies for Manufacturing Companies
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
Essential Infomation Tech presentation.pptx
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PPTX
Transform Your Business with a Software ERP System
Internet Downloader Manager (IDM) Crack 6.42 Build 41
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Upgrade and Innovation Strategies for SAP ERP Customers
medical staffing services at VALiNTRY
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
 
L1 - Introduction to python Backend.pptx
CHAPTER 2 - PM Management and IT Context
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Odoo Companies in India – Driving Business Transformation.pdf
Digital Strategies for Manufacturing Companies
How to Choose the Right IT Partner for Your Business in Malaysia
How to Migrate SBCGlobal Email to Yahoo Easily
Wondershare Filmora 15 Crack With Activation Key [2025
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Essential Infomation Tech presentation.pptx
Odoo POS Development Services by CandidRoot Solutions
2025 Textile ERP Trends: SAP, Odoo & Oracle
wealthsignaloriginal-com-DS-text-... (1).pdf
Transform Your Business with a Software ERP System

Strings in c plus plus

  • 1. STRINGS IN C++ CREATED BY: ________________ Instructor: _________________ _
  • 3. WHAT IS STRING ‱ Like int, double, char, and bool, “String” is a datatype. ‱ Strings are used for storing text (names, sentences, phrases, etc). ‱ For example: string name = “Pakistan”;
  • 4. HOW STRING IS USED A string contains a collection of characters, surrounded by double quotes Example: string greeting = "Hello";
  • 5. USING STRING ‱ To use string, you must include <string> header file in the code ‱ Example // Include the string library #include <string> // Create a string variable string greeting = "Hello";
  • 6. SOME STRING EXAMPLES ‱ String firstName = “John”; ‱ String lastName = “Doe”; // Combining two strings in c++: ‱ String fullName = firstName + lastName;
  • 7. GET STRING FROM USER #include <iostream> #include <string> using namespace std; int main() { string fullName; cout << "Type your full name: "; getline (cin, fullName); cout << "Your name is: " << fullName; return 0; }
  • 8. C++ STRING LENGTH To check how many characters are stored in a string, we use length() function of string. Example: string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; cout << "The length of the txt string is: " << alphabet.length(); //OUTPUT of code: //The length of the txt string is: 26
  • 9. THANK YOU Created by: ___________ Instructor: _________________