Search This Blog

Friday, 21 August 2020

assign fi=unction

 #include<iostream>

#include<conio.h>

using namespace std;

int main()

{

string str="good morning";

cout<<"string is:"<<str<<endl<<endl;

getch();

str.assign("good enening");                            //assign the charactors

cout<<"string after assign() :"<<str<<endl<<endl;


getch();

str.assign("good day");                                  //assign the charactor

cout<<"string after assign:"<<str<<endl;

getch();

string str1,str2;

cout<<"enter first string:"<<ends;

getline(cin,str1);

cout<<"length of string is:"<<str1.length()<<endl;                    //length of the strings calculated

cout<<"capacity of the string is:"<<str1.capacity()<<endl<<endl;       //capacity of the strings caluculated

cout<<"charactor at 5th position is :"<<str1.at(3)<<endl;            //position of element show which element is on which positon

getch();

cout<<"enter the second string:"; 

getline(cin,str2); 

cout<<"length of the string is:"<<str2.length()<<endl;            //  //length of the strings calculated

cout<<"capacity of the string is :"<<str2.capacity()<<endl;       //capacity of the strings caluculated

cout<<"charactor at 6th position is :"<<str2.at(6)<<endl;              //position of element show which element is on which positon

if(str1.compare(str2)==0)                     //string capmared  using campare tool

cout<<"strings are equal";

else

cout<<"strings are not equal"<<"\n\n\n";

cout<<"\nto know the appended the charctor click on enter key:"<<endl;

getch();

str1.append(str2);

cout<<"string after append:"<<str1<<endl;

return 0;

}


No comments:

Post a Comment

Search This Blog

Contact Form

Name

Email *

Message *

Popular Posts