-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.cpp
More file actions
74 lines (56 loc) · 2.18 KB
/
Copy pathstring.cpp
File metadata and controls
74 lines (56 loc) · 2.18 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
65
66
67
68
69
70
71
72
73
74
#include <iostream>
#include <string>
using namespace std;
int main () {
//String
// string greet = "hello ";
// string name ;
// cout << "Enter your name : "; cin >> name ;
// string message = "!, How are you.";
// cout << greet + name + message << endl ;
//String Concatenation
// The + operator can be used between strings to add them together to make a new string. This is called concatenation:
string firstName = "Sahil ";
string lastName = "Max";
string fullName = firstName + lastName;
cout << fullName << endl;
string FirstName = "Sam";
string LastName = "Max";
string FullName = FirstName + " " + LastName;
cout << FullName << endl;
//Concatination by using append
string fName = "Sahil ";
string lName = "Max";
string Name = fName.append(lName);
string nName = Name.append(" k.s");
cout << nName << endl;
//int x and string y can not be added due different data type
//String length and size ie both are same
string text = "\nHello Mrs. Sahil, How is is you cpp going"; //\n is together and takes 1 bit pf storage
cout << text.length() << endl ;
cout << text.size() << endl ;
string str = "docker ps -a list all containers";
cout << str[1] << str[14] << str[15] << str[1] << endl ; //+ can't be use in place of <<
cout << str[str.length()-1] << endl ; //negative indexing just like str[-1] in python
//string modification
string stg = "docker images";
stg[0] = 'D';
cout << stg << endl;
//at(x) function works simmilar to string[x]
string gh = "Git Hub";
cout << "Original string : " << gh << endl ;
cout << "First character : " << gh.at(0) << endl ;
cout << "Second character : " << gh.at(1) << endl ;
cout << "Third character : " << gh.at(2) << endl << endl;
cout << "Last character : " << gh.at(gh.length()-1) << endl;
gh.at(0) = 'D';
gh.at(1) = 'e';
gh.at(2) = 'v';
cout << "Modified string : " << gh << endl;
//special character \', \" ,\\ , \n , \t
string dh = "Dev hub is owned by \"sahil\" and ";
cout << dh << endl;
//c style string
char mystr[] = "hello";
cout << mystr << endl;
}