0% found this document useful (0 votes)
45 views15 pages

Presentation by Rakesh

This document discusses various functions and methods available for strings in C++. Some key functions covered include size() and length() to get the length of a string, swap() to swap two strings, toupper() and tolower() to change case, find() to find a substring, clear() to clear a string, to_string() to convert a number to a string, empty() to check if a string is empty, and pop_back() and push_back() to modify strings. Examples are provided to demonstrate the usage of each function.

Uploaded by

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

Presentation by Rakesh

This document discusses various functions and methods available for strings in C++. Some key functions covered include size() and length() to get the length of a string, swap() to swap two strings, toupper() and tolower() to change case, find() to find a substring, clear() to clear a string, to_string() to convert a number to a string, empty() to check if a string is empty, and pop_back() and push_back() to modify strings. Examples are provided to demonstrate the usage of each function.

Uploaded by

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

STRING

RAKESH AL YADIN
ID:22203121
STRING

String is a class which stores any


series of characters.
#include<iostream>
#include<string>
using namespace std;
int main()
{
string s;
cin>>s;
cout<<s;
return 0;
}
Member Functions
Iterator:
begin() Returns iterator to beginning
end() Returns iterator to end
rbegin() Returns revese iterator to reverse beginning
rend() Returns revese iterator to reverse end
Member Functions
Capacity:
size() Returns lenth of a string
lenth() Returns lenth of a string
resize() Resize string
empty() Test if string is empty
Common Functions For String Operatins

swap() stoi()
size() clear()
length() to_string()
toupper() empty()
tolower() push_back()
find() pop_back()
size() and length()
parameter: No parameter
Results : Returns size in int value

#include<iostream> Output:
#include<string>
using namespace std; 6
int main()
{
string s=“RAKESH”;

cout<< s.size();
return 0;
}
swap()
parameter: String
Results : Swaps to string Variable

#include<iostream> Output:
#include<string>
using namespace std; SHOPNO
int main() RAKESH
{
string s=“RAKESH”, p=“SHOPNO”;
s.swap(p);
cout<<s<<endl<<p<<endl;
return 0;
}
toupper() and tolower()
parameter: character
Results : changes character accordingly

#include<iostream> Output:
#include<string>
using namespace std; rakesh
int main() RAKESH
{ string s=“RAkEsH”;
for(int i=0;i<s.size();i++) { x[i]=tolower(x[i]; }
cout<< s<<endl;
for(int i=0;i<s.size();i++) { x[i]=toupper(x[i]); }
cout<<s<<endl;
return 0;
}
find()
parameter: string
Results : Return integer value

#include<iostream> Output:
#include<string>
using namespace std; 22203121
int main()
{
string s=“22203121”;
int x=stoi(s);
cout<<x;
return 0;
}
clear()
parameter: No Parameter
Results : Return clear string

#include<iostream> Output:
#include<string>
using namespace std; 0
int main()
{
string s=“22203121”;
s.clear();
cout<<s.size();
return 0;
}
to_string()
parameter: Numeric value
Results : Return string

#include<iostream> Output:
#include<string>
using namespace std; 208
int main()
{
string s;
s=to_string(208);
cout<<s;
return 0;
}
empty()
parameter: No parameter
Results : Boolean Type value

#include<iostream> Output:
#include<string>
using namespace std; YES
int main()
{
string s=“habijabi”;
if(s.empty()) cout<<“NO”;
else cout<<“YES”;
return 0;
}
pop_back() and push_back()
parameter: No parameter, character (for push_back)
Results : change the string

#include<iostream> Output:
#include<string>
using namespace std; abc
int main() { abce
string x=“abcd";
x.pop_back();
cout<<x<<endl;
x.push_back(‘e’);
cout<<x;
return 0;
}
THANK YOU

You might also like