Presentation by Rakesh

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 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