Sunday, January 8, 2012

String Part 1




The string class is part of the C++ standard library. A string represents a sequence of characters.
To use the string class, #include the header file:
#include
Constructors:
string ()
- creates an empty string ("")
string ( other_string )
- creates a string identical to other_string
string ( other_string, position, count )
- creates a string that contains count characters from other_string, starting at position. If count is missing (only the first two arguments are given), all the characters from other_string, starting at position and going to the end of other_string, are included in the new string.
string ( count, character )
- create a string containing character repeated count times

MANIPULATING STRING OBJECTS
1.insert()
2.erase()
3.replace()
4.append()
More Methods IN String Class:

size():Number of elements currently
stored
length():Number of elements currently
stored
capacity():Total elements that can be stored
max_size():Maximum size of a string object
that a system can support
emply():Return true or 1 if the string is
empty otherwise returns false or 0
resize():Used to resize a string object
(effects only size and length)
at(): For accessing individual characters
substr(): For retrieving a substring
find(): For finding a specific substring
find_first_of(): For finding the location of first occurrence of the specific
character(s)
find_last_of(): For finding the location of first occurrence of the specific
character(s)
[] operator: For accessing individual character. Makes the string
object to look like an array.
Running Codes
http://pages.cs.wisc.edu/~cs368-1/CppTutorial/NOTES/STRING.html

No comments:

Post a Comment