Wednesday, June 15, 2016

Different uses of string class plus

string name;
getline (cin, name);
// read a whole line into the string name(works like ase gets() )

//swaping
string s1,s2;
cin>>s1>>s2;
swap(s1,s2);

//we could convert the first character of a string to upper case with the following code

string s= "hello";
s[0] = toupper(s[0]);

//we could use that method to control a loop that allows us to convert all the characters to upper case

for (string::size_type i = 0; i < str.length(); i++)
{
    str[i] = toupper (str[i]);
}

// for lowercase we can use tolower() function


to find posintion of a character or substring

string s;
cin>>s;
int p= s.find('a'); ///to find first occurence of a character or substring
int q= s.rfind('a'); ///to find last occurence of a character or substring
cout<<p;

No comments:

Post a Comment

Speedup Android Studio

Go to Help ->Edit Custom VM Options, and chnge this 4 setting. After that close your Android Studio. This settings are for 8gb of ram pc...