Pages

Friday, 10 June 2011

Step-by-Step To perform the basic string operations involves these steps


From Mcgraw hills
Step-by-Step
To perform the basic string operations involves these steps:
1. The string class is declared within the header <string>. Thus, <string> must be
included in any program that uses string.
2. Create a string by using one of its constructors. Three are demonstrated in this
recipe. The first creates an empty string, the second creates a string initialized by
a string literal, and the third creates a string that is initialized by another string.
3. To obtain the length of the longest possible string, call max_size( ).
4. To assign one string to another, use the = operator.
5. To concatenate two string objects, use the + operator.
6. To lexicographically compare two string objects, use the relational operators, such
as > or ==.
7. To obtain a reference to a character at a specified index, use the [ ] indexing operator.
8. To obtain the number of characters currently held by a string, call size( ).
9. To obtain the current capacity of a string, call capacity( ).
10. To specify a capacity, call reserve( ).
11. To remove all or part of the characters from a string, call erase( ).
12. To add a character to the end of a string, call push_back( ).
13. To obtain a substring, call substr( ).

0 comments:

Post a Comment

Search This Blog