// Program 4.8.1 #include #include using namespace std; int main () { char str1[10] = "Hello"; char str2[10] = "World"; char str3[10]; string str4 = "Hello"; string str5 = "World"; string str6; int len1, len2 ; cout << "==============================="<< endl; cout << "Copy string"<< endl; cout << "-------------------------------"<< endl; str6 = str4; cout << "str6 : " << str6 << endl; strcpy( str3, str1); cout << "strcpy( str3, str1) : " << str3 << endl< "<< str4 < "<< str4 < "; cout << str4[4] <
// Program 4.8.1
#include <iostream>
#include <cstring>
using namespace std;
int main ()
{
char str1[10] = "Hello";
char str2[10] = "World";
char str3[10];
string str4 = "Hello";
string str5 = "World";
string str6;
int len1, len2 ;
cout << "==============================="<< endl;
cout << "Copy string"<< endl;
cout << "-------------------------------"<< endl;
str6 = str4;
cout << "str6 : " << str6 << endl;
strcpy( str3, str1);
cout << "strcpy( str3, str1) : " << str3 << endl<<endl;
cout << "==============================="<< endl;
cout << "Concatenates string"<<endl;
cout << "-------------------------------"<< endl;
str6 = str4 + str5;
cout << "str4 + str5 : " << str6 << endl;
strcat( str1, str2);
cout << "strcat( str1, str2): " << str1 << endl<<endl;
cout << "==============================="<< endl;
cout << "String Length"<< endl;
cout << "-------------------------------"<< endl;
len2 = str6.size();
cout << "str6.size() : " << len2 << endl;
len1 = strlen(str1);
cout << "strlen(str6) : " << len1 << endl;
cout << "str6.length() : " << str6.length()<<endl<<endl;
cout << "==============================="<< endl;
cout << "Insert String"<< endl;
cout << "-------------------------------"<< endl;
str4 = str5 ;
str4.insert (5, "s");
cout << "str4.insert (5, ''s'') World --> "<< str4 <<endl<<endl;
cout << "==============================="<< endl;
cout << "Erase String"<< endl;
cout << "-------------------------------"<< endl;
str4.erase (3);
cout << "str4.erase (3), Worlds --> "<< str4 <<endl<<endl;
cout << "==============================="<< endl;
cout << "Capture String"<< endl;
cout << "-------------------------------"<< endl;
str4.insert (3, "lds");
cout << "str4[4] , Worlds --> ";
cout << str4[4] <<endl<<endl;
cout << "==============================="<< endl;
cout << "Compare String"<< endl;
cout << "-------------------------------"<< endl;
char str7 [20]= "Dog";
char str8 [20]= "Chicken";
char str9 [20]= "Cow";
cout << "str7=" << str7 << " , strlen(str7) : " << strlen(str7)<< endl;
cout << "str8=" << str8 << " , strlen(str8) : " << strlen(str8)<< endl;
cout << "str9=" << str9 << " , strlen(str9) : " << strlen(str9)<< endl<<endl;
cout << "strcmp(str7, str8) : " << strcmp(str7, str8) <<endl;
cout << "strcmp(str8, str9) : " << strcmp(str8, str9) <<endl;
cout << "strcmp(str7, str9) : " << strcmp(str7, str9) <<endl<<endl;
cout << "==============================="<< endl;
return 0;
}
TASK
1. Explain in details what the program does?
2. What is the output
Trending now
This is a popular solution!
Step by step
Solved in 2 steps