Inhaltsverzeichnis

to_string()

#include <string>

string to_string(long long val)
string to_string(unsigned long long val)
string to_string(long double val)
 
wstring to_wstring(long long val)
wstring to_wstring(unsigned long long val)
wstring to_wstring(long double val)

Konvertiert Ganzzahl oder Gleitkommazahl in Zeichenkette.

Parameter

val Zahl

Ergebnis

Rückgabewert: Zeichenkette, die dem Zahlwert entspricht.

Vorsicht! Bei kleinen Gleitkommazahlen gehen signifikante Stellen verloren (siehe Beispiel).

Siehe auch

stod(), stoi(), stold().

Beispiel

to_string.cpp
#include <string>
#include <iostream>
 
int main()
{
  std::string s = "Zahlenfolge: ";
 
  for (int i = 0; i < 10; ++i) s += std::to_string(i) + ' '; 
 
  std::cout << s << '\n';
 
  double d = 1e-9; 
  std::cout << d << "==" << std::to_string(d) << "?\n";  // 1e-09==0.000000?
}