How to use to_string() In C++
The to_string() method takes a single integer variable or other data type and converts it into a string.
Syntax: –
string to_string (float value);
Example:
C++
#include <bits/stdc++.h> using namespace std; int main() { float x=5.5; string resultant; resultant=to_string(x); cout << "Converted value from float to String using to_string() is : " <<resultant<<endl; return 0; } |
Output
Converted value from float to String using to_string() is : 5.500000
Explanation: The to_string function converts the given float value into the string.
Convert Float to String In C++
In this article, we learn how we can convert float to string in C++ using different methods:
- Using the to_string()
- Using stringstream
- Using Macros
- Using lexical_cast from the boost library
Contact Us