Condividi tramite


to_string

Converts a value to a string.

string to_string(int Val);
string to_string(unsigned int Val);
string to_string(long Val);
string to_string(unsigned long Val);
string to_string(long long Val);
string to_string(unsigned long long Val);
string to_string(float Val);
string to_string(double Val);
string to_string(long double Val);

Parameters

Parameter

Description

Val

The value to be converted.

Return Value

The string that represents the value.

Remarks

The function converts Val to a sequence of elements stored in an array object Buf internal to the function as if by calling sprintf(Buf, Fmt, Val), where Fmt is

  • "%d" if Val has type int

  • "%u" if Val has type unsigned int

  • "%ld" if Val has type long

  • "%lu" if Val has type unsigned long

  • "%lld" if Val has type long long

  • "%llu" if Val has type unsigned long long

  • "%f" if Val has type float or double

  • "%Lf" if Val has type long double

The function returns string(Buf).

Requirements

Header: <string>

Namespace: std

See Also

Reference

string (C++ STL <string>)

wstring

<string>