Don't hesitate to send in feedback: send an e-mail if you like the C++ Annotations; if you think that important material was omitted; if you find errors or typos in the text or the code examples; or if you just feel like e-mailing. Send your e-mail to Frank B. Brokken.Please state the document version you're referring to, as found in the title (in this document: 10.3.0) and please state chapter and paragraph name or number you're referring to.
All received mail is processed conscientiously, and received suggestions for improvements are usually processed by the time a new version of the Annotations is released. Except for the incidental case I will normally not acknowledge the receipt of suggestions for improvements. Please don't interpret this as me not appreciating your efforts.
C++ offers many solutions for common problems. Most of these facilities are part of the Standard Template Library or they are implemented as generic algorithms (see chapter 19).
Among the facilities C++ programmers have developed over and over again are those manipulating chunks of text, commonly called strings. The C programming language offers rudimentary string support. C's NTBS is the foundation upon which an enormous amount of code has been built (An NTBS (null-terminated byte string, also NTB string) is a character sequence whose highest-addressed element with defined content has the value zero (the terminating null character); no other character in the sequence has the value zero.).
To process text C++ offers a std::string
type. In C++
the traditional C library functions manipulating NTB strings are
deprecated in favor of using string
objects. Many problems in C
programs are caused by buffer overruns, boundary errors and allocation
problems that can be traced back to improperly using these traditional C
string library functions. Many of these problems can be prevented using
C++ string objects.
Actually, string
objects are class type variables, and in that sense
they are comparable to stream objects like cin
and cout
. In this
section the use of string
type objects is covered. The focus is on their
definition and their use. When using string
objects the
member function syntax is commonly used:
stringVariable.operation(argumentList)For example, if
string1
and string2
are variables of type
std::string
, then
string1.compare(string2)can be used to compare both strings.
In addition to the common member functions the string
class also offers a
wide variety of operators, like the assignment (=
) and the comparison
operator (==
). 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
if (string1.compare(string2) == 0)the following is generally preferred:
if (string1 == string2)
To define and use string
-type objects, sources must include the header
file <string>
. To merely declare the string type
the header can be included.
In addition to std::string
, the header file string
defines the
following string types:
std::wstring
, a string type consisting of wchar_t
characters;
std::u16string
, a string type consisting of char16_t
characters;
std::u32string
, a string type consisting of char32_t
characters.
string::npos
is returned. This value is a symbolic
value of type string::size_type
, which is (for all practical
purposes) an (unsigned
) int
.
All string
members accepting string
objects as arguments also accept
char const *
(NTBS) arguments. The same usually holds true
for operators accepting string
objects.
Some string
-members use iterators. Iterators are formally introduced
in section 18.2. Member functions using iterators are listed in
the next section (5.2), but the iterator concept itself
is not further covered by this chapter.
Strings support a large variety of members and operators. A short overview
listing their capabilities is provided in this section, with subsequent
sections offering a detailed discussion. The bottom line: C++ strings are
extremely versatile and there is hardly a reason for falling back on the C
library to process text. C++ strings handle all the required memory
management and thus memory related problems, which is the #1 source of
problems in C programs, can be prevented when C++ strings are
used. Strings do come at a price, though. The class's extensive capabilities
have also turned it into a beast. It's hard to learn and master all its
features and in the end you'll find that not all that you expected is actually
there. For example, std::string
doesn't offer case-insensitive
comparisons. But in the end it isn't even as simple as that. It is there,
but it is somewhat hidden and at this point in the C++ Annotations it's too
early to study into that hidden corner yet. Instead, realize that C's
standard library does offer useful functions that can be used as long as
we're aware of their limitations and are able to avoid their traps. So for
now, to perform a traditional case-insensitive comparison of the contents
of two std::string
objects str1
and str2
the following will do:
strcasecmp(str1.c_str(), str2.c_str());
Strings support the following functionality:
initialization
:when string objects are defined they are always properly initialized. In other words, they are always in a valid state. Strings may be initialized empty or already existing text can be used to initialize strings.
assignment
:strings may be given new values. New values may be assigned using member functions (likeassign
) but a plain assignment operator (i.e.,=
)may also be used. Furthermore, assignment to a character buffer is also supported.
conversions
:the partial or complete contents of string objects may be interpreted
as C strings but the string's contents may also be processed as a series
of raw binary bytes, not necessarily terminating in a 0-valued
character. Furthermore, in many situations plain characters and C strings
may be used where std::string
s are accepted as well.
breakdown
:the individual characters stored in a string can be accessed
using the familiar index operator ([]
) allowing us to either access or
modify information in the middle of a string.
comparisons
:strings may be compared to other strings (NTB strings) using the familiar logical comparison operators==, !=, <, <=, >
and>=
. There are also member functions available offering a more fine-grained comparison.
modification
:the contents of strings may be modified in many ways. Operators are available to add information to string objects, to insert information in the middle of string objects, or to replace or erase (parts of) a string's contents.
swapping
:the string's swapping capability allows us in principle to exchange the contents of two string objects without a byte-by-byte copying operation of the string's contents.
searching
:the locations of characters, sets of characters, or series of characters may be searched for from any position within the string object and either searching in a forward or backward direction.
housekeeping
:several housekeeping facilities are offered: the string's length, or its empty-state may be interrogated. But string objects may also be resized.
stream I/O
:strings may be extracted from or inserted into streams. In addition to plain string extraction a line of a text file may be read without running the risk of a buffer overrun. Since extraction and insertion operations are stream based the I/O facilities are device independent.
object
is always a string
-object;
argument
is a string const &
or a char const *
unless
indicated otherwise. The contents of an argument
never is modified by the
operation processing the argument
;
opos
refers to an offset into an object
string;
apos
refers to an offset into an argument
;
on
represents a number of characters in an object
(starting
at opos
);
an
represents a number of characters in an argument
(starting
at apos
).
Both opos
and apos
must refer to existing offsets, or an exception
(cf. chapter 10) is generated. In contrast, an
and on
may
exceed the number of available characters, in which case only the available
characters are considered.
Many members declare default values for on, an
and apos
. Some members
declare default values for opos
. Default offset values are 0, the default
values of on
and an
is string::npos
, which can be interpreted as
`the required number of characters to reach the end of the string'.
With members starting their operations at the end of the string object's
contents proceeding backwards, the default value of opos
is the index of
the object's last character, with on
by default equal to opos + 1
,
representing the length of the substring ending at opos
.
In the overview of member functions presented below it may be assumed that all these parameters accept default values unless indicated otherwise. Of course, the default argument values cannot be used if a function requires additional arguments beyond the ones otherwise accepting default values.
Some members have overloaded versions expecting an initial argument of type
char const *
. But even if that is not the case the first argument can
always be of type char const *
where a parameter of std::string
is
defined.
Several member functions accept iterators. Section 18.2 covers
the technical aspects of iterators, but these may be ignored at this point
without loss of continuity. Like apos
and opos
, iterators must refer
to existing positions and/or to an existing range of characters within the
string object's contents.
All string
-member functions computing indices return the
predefined constant string::npos
on failure.
The C++14 standard offers the s
literal suffix to indicate that a
std::string
constant is intended when a string literal (like "hello
world"
) is used. When string literals are used in the context of
std::string
objects, this literal suffix is hardly ever required, but it
may come in handy when using the auto
keyword. E.g., auto str = "hello
world"s
defines std::string str
, whereas it would have been a char
const *
if the literal suffix had been omitted.
string
constructors are
available:
string object
:initializesobject
to an empty string. When defining astring
this way no argument list may be specified;
string object(string::size_type count, char ch)
:initializesobject
withcount
charactersch
;
string object(string const &argument)
:initializesobject
withargument
;
string object(std::string const &argument, string::size_type
apos, string::size_type an)
:initializesobject
withargument
's contents starting at index positionapos
, using at mostan
ofargument
's characters;
string object(InputIterator begin, InputIterator end)
:initializesobject
with the characters in the range of characters defined by the twoInputIterators
.
Iterators play an important role in the context of generic algorithms
(cf. chapter 19). The class std::string
defines the following
iterator types:
string::iterator
and string::const_iterator
:
these iterators are forward iterators. Theconst_iterator
is returned bystring const
objects, the plainiterator
is returned by non-const string objects. Characters referred to byiterators
may be modified;
string::reverse_iterator
and string::reverse_const_iterator
:
these iterators are also forward iterators but when incrementing the iterator the previous character in the string object is reached. Other than that they are comparable to, respectively,string::iterator
andstring::const_iterator
.
The following operators are available for string
objects (in the examples
`object' and `argument' refer to existing std::string
objects).
a character, C or C++ string may be assigned to astring
object. The assignment operator returns its left-hand side operand. Example:object = argument; object = "C string"; object = 'x'; object = 120; // same as object = 'x'
the arithmetic additive assignment operator and the addition operator add text to astring
object. The compound assignment operator returns its left-hand side operand, the addition operator returns its result in a temporary string object. When using the addition operator either the left-hand side operand or the right-hand side operand must be astd::string
object. The other operand may be a char, a C string or a C++ string. Example:object += argument; object += "hello"; object += 'x'; // integral expressions are OK argument + otherArgument; // two std::string objects argument + "hello"; // using + at least one "hello" + argument; // std::string is required argument + 'a'; // integral expressions are OK 'a' + argument;
The index operator may be used to retrieveobject
's individual characters, or to assign new values to individual characters of a non-const string object. There is no range-checking (use theat()
member function for that). This operator returns achar &
orchar const &
. Example:object[3] = argument[5];
the logical comparison operators may be applied to two string objects or to a string object and a C string to compare their contents. These operators return abool
value. The==, !=, >, >=, <,
and<=
operators are available. The ordering operators perform a lexicographical comparison of their contents using the ASCII character collating sequence. Example:object == object; // true object != (object + 'x'); // true object <= (object + 'x'); // true
the insertion-operator (cf. section 3.1.4) may be used to insert astring
object into anostream
, the extraction-operator may be used to extract a string object from anistream
. The extraction operator by default first ignores all white space characters and then extracts all consecutively non-blank characters from anistream
. Instead of a string a character array may be extracted as well, but the advantage of using a string object should be clear: the destination string object is automatically resized to the required number of characters. Example:cin >> object; cout << object;
std::string
class offers many member function as well as additional
non-member functions that should be considered part of the string class.
All these functions are listed below in alphabetic order.
The symbolic value string::npos
is defined by the string class. It
represents `index-not-found' when returned by member functions returning
string offset positions. Example: when calling `object.find('x')
' (see
below) on a string object not containing the character 'x'
, npos
is returned, as the requested position does not exist.
The final 0-byte used in C strings to indicate the end of an NTBS is
not considered part of a C++ string, and so the member function will
return npos
, rather than length()
when looking for 0 in a string
object containing the characters of a C string.
Here are the standard functions that operate on objects of the class
string. When a parameter of size_t
is mentioned it may be interpreted as a
parameter of type string::size_type
, but without defining a default
argument value. The type size_type
should be read as
string::size_type
. With size_type
the default argument values
mentioned in section 5.2 apply. All quoted functions are
member functions of the class std::string
, except where indicated
otherwise.
char &at(size_t opos)
:a reference to the character at the indicated position is returned. When called withstring const
objects achar const &
is returned. The member function performs range-checking, raising an exception (that by default aborts the program) if an invalid index is passed.
string &append(InputIterator begin, InputIterator end)
:the characters in the range defined bybegin
andend
are appended to the current string object.
string &append(string const &argument, size_type apos,
size_type an)
:argument
(or a substring) is appended to the current string
object.
string &append(char const *argument, size_type an)
:the firstan
characters ofargument
are appended to the string object.
string &append(size_type n, char ch)
:n
charactersch
are appended to the current string object.
string &assign(string const &argument, size_type
apos, size_type an)
:argument
(or a substring) is assigned to the string object. Ifargument
is of typechar const *
and one additional argument is provided the second argument is interpreted as a value initializingan
, using 0 to initializeapos
.
string &assign(size_type n, char ch)
:n
charactersch
are assigned to the current string object.
char &back()
:returns a reference to the last char
stored inside the string
object. The result is undefined for empty strings.
string::iterator begin()
:an iterator referring to the first character of the current string object is returned. Withconst
string objects aconst_iterator
is returned.
size_type capacity() const
:the number of characters that can currently be stored in the string object without needing to resize it is returned.
string::const_iterator cbegin()
:a const_iterator
referring to the first character of the current
string object is returned.
string::const_iterator cend()
:a const_iterator
referring to the end of the current
string object is returned.
int compare(string const &argument) const
:the text stored in the current string object and the text stored inargument
is compared using a lexicographical comparison using the ASCII character collating sequence. zero is returned if the two strings have identical contents, a negative value is returned if the text in the current object should be ordered before the text inargument
; a positive value is returned if the text in the current object should be ordered beyond the text inargument
.
int compare(size_t opos, size_t on, string const &argument) const
:a substring of the text stored in the current string object is compared to the text stored inargument
. At moston
characters starting at offsetopos
are compared to the text inargument
.
int compare(size_t opos, size_t on, string const &argument,
size_type apos, size_type an)
:a substring of the text stored in the current string object is compared to a substring of the text stored inargument
. At moston
characters of the current string object, starting at offsetopos
, are compared to at mostan
characters ofargument
, starting at offsetapos
. In this caseargument
must be a string object.
int compare(size_t opos, size_t on, char const *argument, size_t an)
:a substring of the text stored in the current string object is compared to a substring of the text stored inargument
. At moston
characters of the current string object starting at offsetopos
are compared to at mostan
characters ofargument
.Argument
must have at leastan
characters. The characters may have arbitrary values: 0-valued characters have no special meanings.
size_t copy(char *argument, size_t on, size_type opos) const
:the contents of the current string object are (partially) copied intoargument
. The actual number of characters copied is returned. The second argument, specifying the number of characters to copy, from the current string object is required. No 0-valued character is appended to the copied string but can be appended to the copied text using an idiom like the following:argument[object.copy(argument, string::npos)] = 0;Of course, the programmer should make sure thatargument
's size is large enough to accomodate the additional 0-byte.
string::const_reverse_iterator crbegin()
:a const_reverse_iterator
referring to the last character of the
current string object is returned.
string::const_reverse_iterator crend()
:a const_reverse_iterator
referring to the begin of the current
string object is returned.
char const *c_str() const
:the contents of the current string object as an NTBS.
char const *data() const
:the raw contents of the current string object are returned. Since this member does not return an NTBS (asc_str
does), it can be used to retrieve any kind of information stored inside the current string object including, e.g., series of 0-bytes:string s(2, 0); cout << static_cast<int>(s.data()[1]) << '\n';
bool empty() const
:true
is returned if the current string object contains no data.
string::iterator end()
:an iterator referring to the position just beyond the last character of the current string object is returned. Withconst
string objects aconst_iterator
is returned.
string &erase(size_type opos, size_type on)
:a (sub)string of the information stored in the current string object is erased.
string::iterator erase(string::iterator begin, string::iterator end)
:the parameterend
is optional. If omitted the value returned by the current object'send
member is used. The characters defined by thebegin
andend
iterators are erased. The iteratorbegin
is returned, which is then referring to the position immediately following the last erased character.
size_t find(string const &argument, size_type opos) const
:the first index in the current string object where argument
is
found is returned.
size_t find(char const *argument, size_type opos, size_type an) const
:the first index in the current string object whereargument
is found is returned. When all three arguments are specified the first argument must be achar const *
.
size_t find(char ch, size_type opos) const
:the first index in the current string object where ch
is found is
returned.
size_t find_first_of(string const &argument,
size_type opos) const
:the first index in the current string object where any character in
argument
is found is returned.
size_type find_first_of(char const *argument, size_type opos,
size_type an) const
:the first index in the current string object where any character inargument
is found is returned. Ifopos
is provided it refers to the first index in the current string object where the search forargument
should start. If omitted, the string object is scanned completely. Ifan
is provided it indicates the number of characters of thechar const *
argument that should be used in the search. It defines a substring starting at the beginning ofargument
. If omitted, all ofargument
's characters are used.
size_type find_first_of(char ch, size_type opos)
:the first index in the current string object where character ch
is
found is returned.
size_t find_first_not_of(char ch, size_type opos) const
:the first index in the current string object where another
character than ch
is found is returned.
size_t find_last_of(string const &argument,
size_type opos) const
:the last index in the current string object where any character in
argument
is found is returned.
size_type find_last_of(char const *argument, size_type opos,
size_type an) const
:the last index in the current string object where any character inargument
is found is returned. Ifopos
is provided it refers to the last index in the current string object where the search forargument
should start. If omitted, the string object is scanned completely. Ifan
is provided it indicates the number of characters of thechar const *
argument that should be used in the search. It defines a substring starting at the beginning ofargument
. If omitted, all ofargument
's characters are used.
size_type find_last_of(char ch, size_type opos)
:the last index in the current string object where character ch
is
found is returned.
size_t find_last_not_of(string const &argument,
size_type opos) const
:the last index in the current string object where any character not
appearing in argument
is found is returned.
char &front()
:returns a reference to the first char
stored inside the string
object. The result is undefined for empty strings.
allocator_type get_allocator()
:returns the allocator of the class std::string
istream &std::getline(istream &istr, string &object,
char delimiter = '\n')
:Note: this is not a member function of the classstring
.
A line of text is read fromistr
. All characters untildelimiter
(or the end of the stream, whichever comes first) are read fromistr
and are stored inobject
. If the delimiter is encountered it is removed from the stream, but is not stored inline
.
If the delimiter is not found,istr.eof
returnstrue
(see section 6.3.1). Since streams may be interpreted asbool
values (cf. section 6.3.1) a commonly encountered idiom to read all lines from a stream successively into a string objectline
looks like this:while (getline(istr, line)) process(line);The contents of the last line, whether or not it was terminated by a delimiter, is eventually also assigned toobject
.
string &insert(size_t opos, string const &argument,
size_type apos, size_type an)
:a (sub)string ofargument
is inserted into the current string object at the current string object's index positionopos
. Arguments forapos
andan
must either both be provided or they must both be omitted.
string &insert(size_t opos, char const *argument,
size_type an)
:argument
(of typechar const *
) is inserted at indexopos
into the current string object.
string &insert(size_t opos, size_t count, char ch)
:Count
charactersch
are inserted at indexopos
into the current string object.
string::iterator insert(string::iterator begin, char ch)
:the characterch
is inserted at the current object's position referred to bybegin
.Begin
is returned.
string::iterator insert(string::iterator begin, size_t count,
char ch)
:Count
charactersch
are inserted at the current object's position referred to bybegin
.Begin
is returned.
string::iterator insert(string::iterator begin, InputIterator
abegin, InputIterator aend)
:the characters in the range defined by theInputIterators abegin
andaend
are inserted at the current object's position referred to bybegin
.Begin
is returned.
size_t length() const
:the number of characters stored in the current string object is returned.
size_t max_size() const
:the maximum number of characters that can be stored in the current string object is returned.
void pop_back()
:The string's last character is removed from the string object.
void push_back(char ch)
:The character ch
is appended to the string object.
void push_front(char ch)
:The character ch
is prepended to the string object.
string::reverse_iterator rbegin()
:a reverse iterator referring to the last character of the current string object is returned. Withconst
string objects areverse_const_iterator
is returned.
string::iterator rend()
:a reverse iterator referring to the position just before the first character of the current string object is returned. Withconst
string objects areverse_const_iterator
is returned.
string &replace(size_t opos, size_t on, string const
&argument, size_type apos, size_type an)
:a (sub)string of characters inobject
are replaced by the (subset of) characters ofargument
. Ifon
is specified as 0argument
is inserted intoobject
at offsetopos
.
string &replace(size_t opos, size_t on, char const *argument,
size_type an)
:a series of characters inobject
are replaced by the firstan
characters ofchar const *
argument.
string &replace(size_t opos, size_t on, size_type count, char ch)
:on
characters of the current string object, starting at index positionopos
, are replaced bycount
charactersch
.
string &replace(string::iterator begin, string::iterator end,
string const &argument)
:the series of characters in the current string object defined by the iteratorsbegin
andend
are replaced byargument
. Ifargument
is achar const *
, an additional argumentan
may be used, specifying the number of characters ofargument
that are used in the replacement.
string &replace(string::iterator begin, string::iterator end,
size_type count, char ch)
:the series of characters in the current string object defined by the iteratorsbegin
andend
are replaced bycount
characters having valuesch
.
string &replace(string::iterator begin, string::iterator end,
InputIterator abegin, InputIterator aend)
:the series of characters in the current string object defined by the iteratorsbegin
andend
are replaced by the characters in the range defined by theInputIterators abegin
andaend
.
void reserve(size_t request)
:the current string object's capacity is changed to at leastrequest
. After calling this member,capacity
's return value will be at leastrequest
. A request for a smaller size than the value returned bycapacity
is ignored. Astd::length_error
exception is thrown ifrequest
exceeds the value returned bymax_size
(std::length_error
is defined in thestdexcept
header). Callingreserve()
has the effect of redefining a string's capacity, not of actually making available the memory to the program. This is illustrated by the exception thrown by the string'sat()
member when trying to access an element exceeding the string'ssize
but not the string'scapacity
.
void resize(size_t size, char ch = 0)
:the current string object is resized tosize
characters. If the string object is resized to a size larger than its current size the additional characters will be initialized toch
. If it is reduced in size the characters having the highest indices are chopped off.
size_t rfind(string const &argument, size_type opos) const
:the last index in the current string object whereargument
is found is returned. Searching proceeds from the current object's offsetopos
back to its beginning.
size_t rfind(char const *argument, size_type opos, size_type an) const
:the last index in the current string object whereargument
is found is returned. Searching proceeds from the current object's offsetopos
back to its beginning. The parameteran
specifies the length of the substring ofargument
to look for, starting atargument
's beginning.
size_t rfind(char ch, size_type opos)const
:the last index in the current string object wherech
is found is returned. Searching proceeds from the current object's offsetopos
back to its beginning.
void shrink_to_fit()
:optionally reduces the amount of memory allocated by a vector to its current size. The implementor is free to ignore or otherwise optimize this request. In order to guarantee a `shrink to fit' operation thestring(stringObject).swap(stringObject)idiom can be used.
size_t size() const
:the number of characters stored in the current string object is
returned. This member is a synonym of length()
.
string substr(size_type opos, size_type on) const
:a substring of the current string object of at moston
characters starting at indexopos
is returned.
void swap(string &argument)
:the contents of the current string object are swapped with the contents ofargument
. For this memberargument
must be a string object and cannot be achar const *
.
std::string
objects. These functions are listed below in alphabetic
order. They are not member functions, but class-less (free) functions declared
in the std
namespace. The <string>
header file must be included
before they can be used.
float stof(std::string const &str, size_t *pos = 0)
:Initial white space characters instr
are ignored. Then the following sequences of characters are converted to afloat
value, which is returned:If
- A decimal floating point constant:
- An optional + or - character
- A series of decimal digits, possibly containing one decimal point character
- An optional e or E character, followed by an optional - or + character, followed by a series of decimal digits
- A hexadecimal floating point constant:
- An optional + or - character
- 0x or 0X
- A series of hexadecimal digits, possibly containing one decimal point character
- An optional p or P character, followed by an optional - or + character, followed by a series of decimal digits
- An infinity expression:
- An optional + or - character
- The words
inf
orinfinity
(case insensitive words)- A `not a number' expression:
- An optional + or - character
- The words
nan
ornan(alphanumeric character sequence)
(nan
is a case insensitive word), resulting in aNaN
floating point valuepos != 0
the index of the first character instr
which was not converted is returned in*pos
. Astd::invalid_argument
exception is thrown if the characters instr
could not be converted to afloat
, astd::out_of_range
exception is thrown if the converted value would have exceeded the range offloat
values.
double stod(std::string const &str, size_t *pos = 0)
:A conversion as described withstof
is performed, but now to a value of typedouble
.
double stold(std::string const &str, size_t *pos = 0)
:A conversion as described withstof
is performed, but now to a value of typelong double
.
int stoi(std::string const &str, size_t *pos = 0,
int base = 10)
:Initial white space characters instr
are ignored. Then all characters representing numeric constants of the number system whosebase
is specified are converted to anint
value, which is returned. An optional + or - character may prefix the numeric characters. Values starting with 0 are automatically interpreted as octal values, values starting with 0x or 0X as hexadecimal characters. The valuebase
must be between 2 and 36. Ifpos != 0
the index of the first character instr
which was not converted is returned in*pos
. Astd::invalid_argument
exception is thrown if the characters instr
could not be converted to anint
, astd::out_of_range
exception is thrown if the converted value would have exceeded the range ofint
values.Here is an example of its use:
int value = stoi(string(" -123")); // assigns value -123 value = stoi(string(" 123"), 0, 5); // assigns value 38
long stol(std::string const &str, size_t *pos = 0,
int base = 10)
:A conversion as described withstoi
is performed, but now to a value of typelong
.
long long stoll(std::string const &str, size_t *pos = 0,
int base = 10)
:A conversion as described withstoi
is performed, but now to a value of typelong long
.
unsigned long stoul(std::string const &str, size_t *pos = 0,
int base = 10)
:A conversion as described withstoi
(not allowing an initial + or - character) is performed, but now to a value of typeunsigned long
.
unsigned long long stoull(std::string const &str,
size_t *pos = 0, int base = 10)
:A conversion as described withstoul
is performed, but now to a value of typeunsigned long long
.
std::string to_string(Type value)
:Type can be of the typesint, long, long long, unsigned, unsigned long, unsigned long long, float, double,
orlong double
. The value of the argument is converted to a textual representation, which is returned as astd::string
value.
std::string to_wstring(Type value)
:The conversion as described atto_string
is performed, returning astd::wstring
.