Quantcast
Channel: How do I convert a long to a string in C++? - Stack Overflow
Browsing latest articles
Browse All 13 View Live
↧

Answer by Yochai Timmer for How do I convert a long to a string in C++?

You can use std::to_string in C++11long val = 12345;std::string my_val = std::to_string(val);

View Article


Answer by jichi for How do I convert a long to a string in C++?

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...

View Article

Answer by Greg Domjan for How do I convert a long to a string in C++?

One of the things not covered by anybody so far, to help you think about the problem further, is what format should a long take when it is cast to a string.Just have a look at a spreedsheet program...

View Article

Answer by Piotr Findeisen for How do I convert a long to a string in C++?

boost::lexical_cast<std::string>(my_long)more here http://www.boost.org/doc/libs/1_39_0/libs/conversion/lexical_cast.htm

View Article

Answer by beef2k for How do I convert a long to a string in C++?

I don't know what kind of homework this is, but most probably the teacher doesn't want an answer where you just call a "magical" existing function (even though that's the recommended way to do it), but...

View Article


Answer by Gordon Freeman for How do I convert a long to a string in C++?

Well if you are fan of copy-paste, here it is:#include <sstream>template <class T>inline std::string to_string (const T& t){ std::stringstream ss; ss << t; return ss.str();}

View Article

Answer by Fred Larson for How do I convert a long to a string in C++?

There are several ways. Read The String Formatters of Manor Farm for an in-depth comparison.

View Article

Answer by dreadwail for How do I convert a long to a string in C++?

int main(){ long mylong = 123456789; string mystring; stringstream mystream; mystream << mylong; mystring = mystream.str(); cout << mystring << "\n"; return 0;}

View Article


Answer by cmaxo for How do I convert a long to a string in C++?

The way I typically do it is with sprintf. So for a long you could do the following assuming that you are on a 32 bit architecture:char buf[5] = {0}; // one extra byte for null sprintf(buf, "%l",...

View Article


Answer by Martin Beckett for How do I convert a long to a string in C++?

#include <sstream> .... std::stringstream ss; ss << a_long_int; // or any other type std::string result=ss.str(); // use .str() to get a string back

View Article

Answer by Skurmedel for How do I convert a long to a string in C++?

You could use stringstream.#include <sstream>// ...std::string number;std::stringstream strstream;strstream << 1L;strstream >> number;There is usually some proprietary C functions in...

View Article

Answer by Don for How do I convert a long to a string in C++?

Check out std::stringstream.

View Article

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

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

View Article

Browsing latest articles
Browse All 13 View Live