Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert a long to a string in C++?

Tags:

c++

How do I convert a long to a string in C++?

like image 241
Arnis Lapsa Avatar asked Jun 03 '09 22:06

Arnis Lapsa


People also ask

How can a number be converted to a string?

We can convert int to String in java using String. valueOf() and Integer. toString() methods. Alternatively, we can use String.

How do I convert a number to a string in C++?

The next method in this list to convert int to string in C++ is by using the to_string() function. This function is used to convert not only the integer but numerical values of any data type into a string. The to_string() method is included in the header file of the class string, i.e., <string> or <cstring>.


1 Answers

In C++11, there are actually std::to_string and std::to_wstring functions in <string>.

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); 
like image 154
jichi Avatar answered Oct 06 '22 00:10

jichi