VOOZH about

URL: https://www.geeksforgeeks.org/cpp/stdto_string-in-cpp/

⇱ std::to_string in C++ - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

std::to_string in C++

Last Updated : 24 Sep, 2024

In C++, the std::to_string function is used to convert numerical values into the string. It is defined inside <string> header and provides a simple and convenient way to convert numbers of any type to strings.

In this article, we will learn how to use std::to_string() in C++.

Syntax

std::to_string(val);

Parameters

  • val: It is the value which we have to convert into string. It can be of any numeric data type like integer, long long, double, float, long double.

Return Value

  • A string containing the representation of val as a sequence of characters.

Example of std::to_string()


Output
Numbers as String: 
42
3.141590
1.234000


Comment
Article Tags: