Strings in C++ C++ doesnt have any data type to hold words or sentences.Instead it has 'char' datatype which can hold single characters.So we manipulate these 'char' variables by using arrays,i.e. we use character arrays to store strings(words or sentences).
There are many operations that can be performed on strings.Programs can be written in C++ to count the number of characters in a string(with/without counting balnk spaces),programs can also check if a given string is palindrome('malayalam' which is the name of a south indian language, is a palindrome string,it is the same whichever way u read it-left to right or right to left).There are programs to join two strings,count the ocurrences of specific letters in a string.
Here is an example of how to use a character array to store a string:
char str[6];
This brings us to a special characteristic of character arrays used to store strings.Unlike a arrays of othe data types a character array ,str[6] in this case will only be able to store 5 elements.This is because the last char array variable is used to store the '/0' character.This is used to tell the compilor that the string has ended.
The following programmes are available:
- Program that srips comments found between /* and */ in a string entered by the user.
- Program that counts the number of occourances of a pair of letters in a string.
- Program to compare two string without using strcomp() function.
- Program to concatenate(join) two strings.
- Program to count the lenght of a string.
|