A string is a collection of two or more characters which are terminated by NULL value. String is always written in double quotes ( “ ” ). C string is very complex and insufficient i.e. it is difficult to perform string operations on it because here we can use a character array to store string in memory and loop for accessing string. To solve this problem, C++ language has a container class string which defines all the objects of string and string handling function. It is stored in C++ language library as string.h header file.
Operations performed on string –
1. Creating string object.
2. Reading a string object from keyword.
3. Display string object.
4. Finding sub-string from string object.
5. Comparing string object.
6. Coping string object.
7. Merging string object.
8. Displaying characteristics of string object.
9. Swapping string objects.
10. Accessing characters from string objects.
Name
of some important string constructors, member functions and operators are as
follows –
Constructor
|
Usage
|
String ( )
|
For creating
empty string.
|
String
(const char *str )
|
For creating
string object from a NULL terminated string.
|
String (const
string &str )
|
For creating
a string object from another string object.
|
Member
function
|
Task
|
append( )
|
append( ) a part of string at the end of another
string.
|
assign( )
|
It is a partial string.
|
begin( )
|
Written start of string.
|
compare( )
|
Comparing two strings.
|
empty( )
|
Return true of string is empty.
|
end( )
|
Return end of string.
|
length( )
|
Return length or number of characters.
|
swap( )
|
Swapping of two strings.
|
Insert( )
|
Insert characters in specified location in string.
|
remove( )
|
Remove characters from string.
|
find( )
|
Find sub-string.
|
Operators
|
Meanings
|
=
|
Assign or equal to.
|
+
|
Concate (addition).
|
+=
|
Concate assign
|
==
|
Equality
|
!=
|
Inequality
|
<
|
Less than
|
<=
|
Less than equal
|
>
|
Greater than
|
>=
|
Greater than equal
|
[ ]
|
Script
|
<<
|
Output or insertion
|
>>
|
Input or extraction
|
No comments:
Post a Comment