És un dels mètodes per convertir el valor en cadena.
Els altres són-
Mitjançant l'ús de la classe stringstream
Mitjançant l'ús del mètode to_string().
Mitjançant l'ús de boost.lexical cast
El mètode to_string() pren una sola variable entera o un altre tipus de dades i es converteix en la cadena.
Converteix el valor numèric en cadena Sintaxi:
canviar el nom al directori de Linux
string to_string (int val); string to_string (long val); string to_string (long long val); string to_string (unsigned val); string to_string (unsigned 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 : val - Numerical value. Return Value : A string object containing the representation of val as a sequence of characters.>
CPP
menú de configuració del telèfon Android
// CPP program to illustrate> // std::to_string> #include> // Driver code> int> main()> {> > int> var1=16;> > > // Converting float to string> > std::string str1 = std::to_string(12.10);> > // Converting integer to string> > std::string str2 = std::to_string(9999);> > > // Converting integer to string by taking a variable> > std::string str3 = std::to_string(var1);> > // Printing the strings> > std::cout << str1 <<> '
'> ;> > std::cout << str2 <<> '
'> ;> > std::cout << str3 <<> '
'> ;> > return> 0;> }> |
>
>
sistema de fitxers linuxSortida
12.100000 9999 16>
Problema: Trobeu un dígit específic en un nombre enter donat. Exemple:
Input : number = 10340, digit = 3 Output : 3 is at position 3>
Implementació:
CPP
java char a cadena
// CPP code to find a digit in a number> // using std::tostring> #include> // Driver code> int> main()> {> > // Converting number to string> > std::string str = std::to_string(9954);> > // Finding 5 in the number> > std::cout <<> '5 is at position '> << str.find(> '5'> ) + 1;> }> |
>
avantatges de l'electricitat
>
Sortida:
5 is at position 3>