File: string.yo

package info (click to toggle)
c%2B%2B-annotations 13.02.02-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,576 kB
  • sloc: cpp: 25,297; makefile: 1,523; ansic: 165; sh: 126; perl: 90; fortran: 27
file content (53 lines) | stat: -rw-r--r-- 2,544 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
bf(C++) offers many solutions for common problems. Most of these facilities
are part of the em(Standard Template Library) or they are implemented as
em(generic algorithms) (see chapter ref(GENERIC)).

Among the facilities bf(C++) programmers have developed over and over again
are those manipulating chunks of text, commonly called em(strings). The bf(C)
programming language offers rudimentary string support.

To process text bf(C++) offers a hi(string)tt(std::string) type. In bf(C++)
the traditional bf(C) library functions manipulating NTB strings are
deprecated in favor of using tt(string) objects. Many problems in bf(C)
programs are caused by buffer overruns, boundary errors and allocation
problems that can be traced back to improperly using these traditional bf(C)
string library functions. Many of these problems can be prevented using
bf(C++) string objects.

Actually, tt(string) objects are em(class type) variables, and in that sense
they are comparable to stream objects like tt(cin) and tt(cout). In this
section the use of tt(string) type objects is covered. The focus is on their
definition and their use. When using tt(string) objects the
    emi(member function) em(syntax) is commonly used:
    verb(        stringVariable.operation(argumentList))

For example, if tt(string1) and tt(string2) are variables of type
tt(std::string), then
    verb(        string1.compare(string2))

can be used to compare both strings.

In addition to the common member functions the tt(string) class also offers a
wide variety of em(operators), like the assignment (tt(=)) and the comparison
operator (tt(==)). Operators often result in code that is easy to understand
and their use is generally preferred over the use of member functions offering
comparable functionality. E.g., rather than writing
        verb(    if (string1.compare(string2) == 0))

the following is generally preferred:
        verb(    if (string1 == string2))

To define and use tt(string)-type objects, sources must include the header
file tthi(string). To merely hi(string: declaring) em(declare) the string type
the header i(iosfwd) can be included.

In addition to tt(std::string), the header file tt(string) defines the
following string types:
    itemization(
    itht(wstring)(std::wstring), a string type consisting of tt(wchar_t)
        characters;
    itht(u16string)(std::u16string), a string type consisting of tt(char16_t)
        characters; 
    itht(u32string)(std::u32string), a string type consisting of tt(char32_t)
        characters. 
    )