-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringS.cpp
More file actions
64 lines (61 loc) · 1.44 KB
/
Copy pathStringS.cpp
File metadata and controls
64 lines (61 loc) · 1.44 KB
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
59
60
61
62
63
64
//Standard Library of String class
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[])
{
string s1,s2,s3;
s1 = "hello";
//character array string
char str[10]="Student";
//assining string to anther string
s2 = str;
cout<<s2<<endl;
//concatenate string
s3 = s2+str;
cout<<s3<<endl;
//user input in string object
string st;
// cout<<"\nEnter name ";
// cin>>st;
// cout<<"Your name is "<<st<<endl;
st.assign("This is assing\n");
cout<<st;
//insert string at index
st.insert(3,"world");
cout<<st<<endl;
//repalce string
st.replace(2,6,"Test");
cout<<st<<endl;
//erase string
st.erase();
cout<<st<<endl;
//append in string
st.append("This is demo text.");
cout<<st<<endl;
//find string
cout<<st.find("text");
//compare string
/*
0 = same string
-1 = dictionary order
1 = opposite of dictionary order
*/
int x = s2.compare(s1);
cout<<"After compare "<<x<<endl;
//convert string
string str1,str2;
char test[20]="hello world";
str1.assign("This is string 1.");
str2 = "This is string 2.";
//convert in character string
strcpy(test,str1.c_str());
cout<<test<<endl;
//size of string
cout<<"String size is"<<str2.size();
cout<<"String size is"<<str1.size();
return 0;
}