-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlec1_basicOpns.cpp
58 lines (50 loc) Β· 1.08 KB
/
lec1_basicOpns.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include<iostream>
using namespace std;
int main()
{
// char name[5];
// cout<<"Enter your name:";
// cin>>name;
// cout<<name<<endl;
// const char name2[] = {'A','B','C'};
// // cout<<name2<<endl;
// string s;
// cout<<"Enter any string value:";
// cin>>s;
// cout<<s<<endl;
// string s2;
// cout<<"Enter string with space:";
// getline(cin,s2);
// cout<<s2;
// combine
string s3 = "hel" , s4 = "lo";
s3+=s4;
cout<<s3;
//pushback:- only 1 character
s4.push_back('j');
cout<<s4;
//append :- string
s4.append("jj");
cout<<s4;
//escape character
string s5 = "Rohit is a \"good\" boy";
cout<<endl<<s5;
//program to reverse the string
string rev = "Rohit";
int s = 0 , e = rev.size()-1;
while(s<e)
{
swap(rev[s] , rev[e]);
s++ , e--;
}
cout<<endl<<rev;
// program to find length manually
string str = "ChennaiSuperKings";
int i = 0 ,len = 0;
while(str[i]!='\0')
{
len++;
i++;
}
cout<<endl<<"Length is "<<len;
}