Wednesday, June 22, 2022

FINDING A USERNAME FROM EMAIL ADDRESS

 # include<iostream>

using namespace std;

    


int main()

{

string email="Hassu@gmail.com";

int i=(int)email.find('@');

string uname=email.substr(0,i);

cout<<"user name is "<<uname<<endl;

return 0;

}

USING ITERATORS IN STRING

 #include<iostream>

#include<string>


using namespace std;


int main()

{

    string str="the devil";

    string::iterator it;

    for(it=str.begin();it!=str.end();it++)

    {

        *it;

    }

    cout<<str<<endl;

    

    for(it=str.begin();it!=str.end();it++)

    {

        *it=*it-32;

    }

    cout<<str<<endl;

    

    string::reverse_iterator it;

    for(it=str.rbegin();it!=str.rend();it++)

    {

        *it;

    }

    cout<<str<<endl;

    for(it=str.rbegin();it!=str.rend();it++)

    {

        *it=*it-32;

    }

    cout<<str<<endl;

    return 0;

}

OPERATOR IN STRING

 #include<iostream>

#include<cstring>


using namespace std;


int main()

{

    string str1="the devil is me";

    string str2=" oh really";

    cout<<str1.substr(3);

    cout<<str1.compare(str2);

    str1[4]='F';

    cout<<str1<<endl;

    str1=str1+str2;

    cout<<str1<<endl;

    return 0;

}

COPY AND FINDING STRING

 #include<iostream>

#include<cstring>


using namespace std;


int main()

{

    string s="welcome to my world";

    char str[10];

    s.copy(str,s.length());

    cout<<str<<endl;

    cout<<s.find("to")<<endl;

    cout<<s.find("is")<<endl;

    cout<<s.rfind("o")<<endl;

    cout<<s.find_first_of('o');

    cout<<s.find_last_of('o');

    return 0;

}

REPLACE AND SWAPING THE STRING

 #include<iostream>

using namespace std;



int main()

{

    string str1="hello";

    string str2="world";

    cout<<str1.capacity()<<endl;

    cout<<str1.append(" welcome to us");

    cout<<str1.insert(0,"::");

    cout<<str1.replace(9,20,"::");

    str1.swap(str2);

    str1.push_back('y');

    cout<<str1<<endl;

    cout<<str1.capacity()<<endl;


    return 0;

}

ALL CLASS OF STRING

 #include<iostream>

using namespace std;



int main()

{

    string str="hello world ";

    

    

    cout<<str.length()<<endl;

    cout<<str.size()<<endl;

    cout<<str.capacity()<<endl;

    cout<<str.size()<<endl;

    cout<<str.max_size()<<endl;

    cout<<str.empty()<<endl;

    cout<<str<<endl;


    return 0;

}

Tuesday, June 21, 2022

STRCPY FUNCATION

 #include<iostream>

#include<cstring>

using namespace std;



int main()

{

     char s1[20]="GOOD";

     char s2[10]=" ";

     

     

     strcpy(s2,s1);

     

     cout<<s2<<endl;

     

     return 0;

}

STRLEN FUNCATION

 #include<iostream>

#include<cstring>

using namespace std;



int main()

{

    char *s;

    

    cout<<" Enter the string :";

    cin.getline(s,100);

    

    

    cout<<"lemght  "<< strlen(s) <<endl;

    

    return 0;

}

CONSTRUCTURE IN PARENT CLASS

class Parent {     public Parent()     {         System.out.println("Parent Constrcutor");     }              } class Child extend...