<s>
The	O
C++	B-Language
programming	I-Language
language	I-Language
has	O
support	O
for	O
string	O
handling	O
,	O
mostly	O
implemented	O
in	O
its	O
standard	B-Language
library	I-Language
.	O
</s>
<s>
The	O
language	O
standard	O
specifies	O
several	O
string	O
types	O
,	O
some	O
inherited	O
from	O
C	B-Language
,	O
some	O
designed	O
to	O
make	O
use	O
of	O
the	O
language	O
's	O
features	O
,	O
such	O
as	O
classes	O
and	O
RAII	B-Application
.	O
</s>
<s>
Since	O
the	O
initial	O
versions	O
of	O
C++	B-Language
had	O
only	O
the	O
"	O
low-level	O
"	O
C	B-Language
string	I-Language
handling	I-Language
functionality	O
and	O
conventions	O
,	O
multiple	O
incompatible	O
designs	O
for	O
string	O
handling	O
classes	O
have	O
been	O
designed	O
over	O
the	O
years	O
and	O
are	O
still	O
used	O
instead	O
of	O
std::string	O
,	O
and	O
C++	B-Language
programmers	O
may	O
need	O
to	O
handle	O
multiple	O
conventions	O
in	O
a	O
single	O
application	O
.	O
</s>
<s>
The	O
type	O
is	O
the	O
main	O
string	O
datatype	O
in	O
standard	O
C++	B-Language
since	O
1998	O
,	O
but	O
it	O
was	O
not	O
always	O
part	O
of	O
C++	B-Language
.	O
</s>
<s>
From	O
C	B-Language
,	O
C++	B-Language
inherited	O
the	O
convention	O
of	O
using	O
null-terminated	B-Data_Structure
strings	I-Data_Structure
that	O
are	O
handled	O
by	O
a	O
pointer	O
to	O
their	O
first	O
element	O
,	O
and	O
a	O
library	O
of	O
functions	O
that	O
manipulate	O
such	O
strings	O
.	O
</s>
<s>
In	O
modern	O
standard	O
C++	B-Language
,	O
a	O
string	O
literal	O
such	O
as	O
still	O
denotes	O
a	O
NUL-terminated	O
array	O
of	O
characters	O
.	O
</s>
<s>
Using	O
C++	B-Language
classes	O
to	O
implement	O
a	O
string	O
type	O
offers	O
several	O
benefits	O
of	O
automated	O
memory	B-General_Concept
management	I-General_Concept
and	O
a	O
reduced	O
risk	O
of	O
out-of-bounds	O
accesses	O
,	O
and	O
more	O
intuitive	O
syntax	O
for	O
string	O
comparison	O
and	O
concatenation	O
.	O
</s>
<s>
Over	O
the	O
years	O
,	O
C++	B-Language
application	O
,	O
library	O
and	O
framework	O
developers	O
produced	O
their	O
own	O
,	O
incompatible	O
string	O
representations	O
,	O
such	O
as	O
the	O
one	O
in	O
T	O
's	O
Standard	O
Components	O
library	O
(	O
the	O
first	O
such	O
implementation	O
,	O
1983	O
)	O
or	O
the	O
type	O
in	O
Microsoft	O
's	O
MFC	B-Language
.	O
</s>
<s>
While	O
standardized	O
strings	O
,	O
legacy	O
applications	O
still	O
commonly	O
contain	O
such	O
custom	O
string	O
types	O
and	O
libraries	O
may	O
expect	O
C-style	O
strings	O
,	O
making	O
it	O
"	O
virtually	O
impossible	O
"	O
to	O
avoid	O
using	O
multiple	O
string	O
types	O
in	O
C++	B-Language
programs	I-Language
and	O
requiring	O
programmers	O
to	O
decide	O
on	O
the	O
desired	O
string	O
representation	O
ahead	O
of	O
starting	O
a	O
project	O
.	O
</s>
<s>
In	O
a	O
1991	O
retrospective	O
on	O
the	O
history	O
of	O
C++	B-Language
,	O
its	O
inventor	O
Bjarne	O
Stroustrup	O
called	O
the	O
lack	O
of	O
a	O
standard	O
string	O
type	O
(	O
and	O
some	O
other	O
standard	O
types	O
)	O
in	O
C++	B-Language
1.0	O
the	O
worst	O
mistake	O
he	O
made	O
in	O
its	O
development	O
;	O
"	O
the	O
absence	O
of	O
those	O
led	O
to	O
everybody	O
re-inventing	O
the	O
wheel	O
and	O
to	O
an	O
unnecessary	O
diversity	O
in	O
the	O
most	O
fundamental	O
classes	O
"	O
.	O
</s>
<s>
does	O
not	O
actually	O
copy	O
the	O
content	O
of	O
to	O
;	O
instead	O
,	O
both	O
strings	O
share	O
their	O
contents	O
and	O
a	O
reference	B-General_Concept
count	I-General_Concept
on	O
the	O
content	O
is	O
incremented	O
.	O
</s>
<s>
Copy-on-write	B-Language
can	O
make	O
major	O
performance	O
changes	O
to	O
code	O
using	O
strings	O
(	O
making	O
some	O
operations	O
much	O
faster	O
and	O
some	O
much	O
slower	O
)	O
.	O
</s>
<s>
Though	O
no	O
longer	O
uses	O
it	O
,	O
many	O
(	O
perhaps	O
most	O
)	O
alternative	O
string	O
libraries	O
still	O
implement	O
copy-on-write	B-Language
strings	O
.	O
</s>
<s>
Some	O
string	O
implementations	O
store	O
16-bit	O
or	O
32-bit	O
code	O
points	O
instead	O
of	O
bytes	B-Application
,	O
this	O
was	O
intended	O
to	O
facilitate	O
processing	O
of	O
Unicode	O
text	O
.	O
</s>
<s>
However	O
,	O
it	O
means	O
that	O
conversion	O
to	O
these	O
types	O
from	O
or	O
from	O
arrays	O
of	O
bytes	B-Application
is	O
dependent	O
on	O
the	O
"	O
locale	O
"	O
and	O
can	O
throw	O
exceptions	O
.	O
</s>
<s>
Any	O
processing	O
advantages	O
of	O
16-bit	O
code	O
units	O
vanished	O
when	O
the	O
variable-width	O
UTF-16	O
encoding	O
was	O
introduced	O
(	O
though	O
there	O
are	O
still	O
advantages	O
if	O
you	O
must	O
communicate	O
with	O
a	O
16-bit	O
API	O
such	O
as	O
Windows	B-Application
)	O
.	O
</s>
<s>
Qt	B-Language
's	O
is	O
an	O
example	O
.	O
</s>
<s>
The	O
class	O
is	O
the	O
standard	O
representation	O
for	O
a	O
text	O
string	O
since	O
C++98	O
.	O
</s>
<s>
An	O
can	O
be	O
constructed	O
from	O
a	O
C-style	O
string	O
,	O
and	O
a	O
C-style	O
string	O
can	O
also	O
be	O
obtained	O
from	O
one	O
.	O
</s>
<s>
The	O
copy-on-write	B-Language
strategy	O
was	O
deliberately	O
allowed	O
by	O
the	O
initial	O
C++	B-Language
Standard	O
for	O
because	O
it	O
was	O
deemed	O
a	O
useful	O
optimization	O
,	O
and	O
used	O
by	O
nearly	O
all	O
implementations	O
.	O
</s>
<s>
However	O
,	O
there	O
were	O
mistakes	O
,	O
in	O
particular	O
the	O
returned	O
a	O
non-const	O
reference	O
in	O
order	O
to	O
make	O
it	O
easy	O
to	O
port	O
C	B-Language
in-place	O
string	O
manipulations	O
(	O
such	O
code	O
often	O
assumed	O
one	O
byte	B-Application
per	O
character	O
and	O
thus	O
this	O
may	O
not	O
have	O
been	O
a	O
good	O
idea	O
!	O
)	O
</s>
<s>
This	O
caused	O
some	O
implementations	O
to	O
abandon	O
copy-on-write	B-Language
.	O
</s>
<s>
It	O
was	O
also	O
discovered	O
that	O
the	O
overhead	O
in	O
multi-threaded	B-Operating_System
applications	O
due	O
to	O
the	O
locking	O
needed	O
to	O
examine	O
or	O
change	O
the	O
reference	B-General_Concept
count	I-General_Concept
was	O
greater	O
than	O
the	O
overhead	O
of	O
copying	O
small	O
strings	O
on	O
modern	O
processors	O
(	O
especially	O
for	O
strings	O
smaller	O
than	O
the	O
size	O
of	O
a	O
pointer	O
)	O
.	O
</s>
<s>
The	O
optimization	O
was	O
finally	O
disallowed	O
in	O
C++11	B-Language
,	O
with	O
the	O
result	O
that	O
even	O
passing	O
a	O
as	O
an	O
argument	O
to	O
a	O
function	O
,	O
viz	O
.	O
</s>
<s>
In	O
C++17	B-Language
added	O
a	O
new	O
class	O
that	O
is	O
only	O
a	O
pointer	O
and	O
length	O
to	O
read-only	O
data	O
,	O
makes	O
passing	O
arguments	O
far	O
faster	O
than	O
either	O
of	O
the	O
above	O
examples	O
:	O
</s>
<s>
is	O
a	O
typedef	B-Language
for	O
a	O
particular	O
instantiation	O
of	O
the	O
template	B-Application
class	I-Application
.	O
</s>
<s>
There	O
is	O
a	O
similar	O
class	O
,	O
which	O
consists	O
of	O
,	O
and	O
is	O
most	O
often	O
used	O
to	O
store	O
UTF-16	O
text	O
on	O
Windows	B-Application
and	O
UTF-32	O
on	O
most	O
Unix-like	B-Operating_System
platforms	O
.	O
</s>
<s>
The	O
C++	B-Language
standard	O
,	O
however	O
,	O
does	O
not	O
impose	O
any	O
interpretation	O
as	O
Unicode	O
code	O
points	O
or	O
code	O
units	O
on	O
these	O
types	O
and	O
does	O
not	O
even	O
guarantee	O
that	O
a	O
holds	O
more	O
bits	O
than	O
a	O
.	O
</s>
<s>
To	O
resolve	O
some	O
of	O
the	O
incompatibilities	O
resulting	O
from	O
'	O
s	O
properties	O
,	O
C++11	B-Language
added	O
two	O
new	O
classes	O
:	O
and	O
(	O
made	O
up	O
of	O
the	O
new	O
types	O
and	O
)	O
,	O
which	O
are	O
the	O
given	O
number	O
of	O
bits	O
per	O
code	O
unit	O
on	O
all	O
platforms	O
.	O
</s>
<s>
C++11	B-Language
also	O
added	O
new	O
string	O
literals	O
of	O
16-bit	O
and	O
32-bit	O
"	O
characters	O
"	O
and	O
syntax	O
for	O
putting	O
Unicode	O
code	O
points	O
into	O
null-terminated	O
(	O
C-style	O
)	O
strings	O
.	O
</s>
<s>
As	O
of	O
C++11	B-Language
,	O
only	O
,	O
,	O
and	O
specializations	O
are	O
required	O
to	O
be	O
implemented	O
.	O
</s>
<s>
A	O
is	O
also	O
a	O
Standard	B-Language
Library	I-Language
container	I-Language
,	O
and	O
thus	O
the	O
Standard	B-Language
Library	I-Language
algorithms	I-Language
can	O
be	O
applied	O
to	O
the	O
code	O
units	O
in	O
strings	O
.	O
</s>
<s>
The	O
design	O
of	O
has	O
been	O
held	O
up	O
as	O
an	O
example	O
of	O
monolithic	O
design	O
by	O
Herb	O
Sutter	O
,	O
who	O
reckons	O
that	O
of	O
the	O
103	O
member	O
functions	O
on	O
the	O
class	O
in	O
C++98	O
,	O
71	O
could	O
have	O
been	O
decoupled	B-Application
without	O
loss	O
of	O
implementation	O
efficiency	O
.	O
</s>
