DIR Return Create A Forum - Home
---------------------------------------------------------
gworld
HTML https://gworld.createaforum.com
---------------------------------------------------------
*****************************************************
DIR Return to: C++PROGRAMMING LANGUAGE
*****************************************************
#Post#: 129--------------------------------------------------
C++ STRINGS
By: eba95 Date: July 30, 2010, 8:52 pm
---------------------------------------------------------
C++ Strings
The ba s i c _ s t r i ng class provides a
useful way to manipulate and store
sequences of characters. It is defined
as a basic template class in the s t d
namespace in the < s t r i ng> header
file.
t e m p l a t e < t y pe na m e C ha r , t y pe na m e T r a i t
s = c ha r _ t r a i t s < C ha r > , t y pe na m e A l l o c
c l a s s ba s i c _ s t r i ng ;
The C++ standard library provides
two specializations of class
ba s i c _ s t r i ng.
t y pe de f ba s i c _ s t r i ng< c ha r > s t r i ng ;
t y pe de f ba s i c _ s t r i ng< w c ha r _ t > w s t r i ng ;
In the following sections, s t r i ng
means any specialization of class
ba s i c _ s t r i ng, and C ha r means its
character type.
Constructors create strings from arrays of
characters and other strings
Operators concatenate strings, assign strings,
use strings for I/O, compare strings
append append characters and strings onto a
string
assign give a string values from strings of
characters and other C++ strings
at returns the character at a specific
location
begin returns an iterator to the beginning
of the string
c_str returns a non-modifiable standard C
character array version of the string
capacity returns the number of characters
that the string can hold
clear removes all characters from the
string
compare compares two strings
copy copies characters from a string into
an array
data returns a pointer to the first
character of a string
empty true if the string has no characters
end returns an iterator just past the last
character of a string
erase removes characters from a string
find find characters in the string
find_first_not_of find first absence of characters
find_first_of find first occurrence of characters
find_last_not_of find last absence of characters
find_last_of find last occurrence of characters
getline read data from an I/O stream into a
string
insert insert characters into a string
length returns the length of the string
max_size returns the maximum number of
characters that the string can hold
npos a special value that indicates “not
found” or “all remaining characters”
push_back add a character to the end of the
string
rbegin returns a reverse_iterator to the end
of the string
rend returns a reverse_iterator to the
beginning of the string
replace replace characters in the string
reserve sets the minimum capacity of the
string
resize change the size of the string
rfind find the last occurrence of a
substring
size returns the number of items in the
string
substr returns a certain substring
swap swap the contents of this string with
another
*****************************************************