String array and Char Array in C++ | Confusion Solved!

String Array Function

string str="harsh";


Length

str.length();
or str.size();
or 
int length =sizeof(a)/sizeof(a[0]);


Concatenation
result =string1+string2;


Char Array Functions 
//cin and cout works here
char str[100]="harsh";


Length 
strlen(str);


Concatenation
strcat(dest , source) 
Stores the merged string in destination string.

strncat(dest,source,n)
n is how much letters of source string you want to copy in destination string
result in destination.
Comparison

//If the difference is equal to zero, then string1 = string2
//If the difference is positive, then string1 > string2
//If the difference is negative, then string1 < string2
strcmp(str1, str2)
strncmp(str1,str2,n)
This function is used for comparing first ‘n’ characters of 2 strings.


Reversing
strrev(string)
reverses the string


Substring
strstr(mainstring,substring)
Searches the substring in the main string and returns the (position of its first occurence -1).







 

Comments