torkell: (Default)
Thomas ([personal profile] torkell) wrote2009-04-14 05:56 pm

(no subject)

Today's starter for ten:

In C++, just how is one meant to go about transforming an integer into a string? Almost every other language I've used can do this in one statement, without having to preallocate the string.

[identity profile] olego.livejournal.com 2009-04-16 08:26 pm (UTC)(link)
If you're using STL:

int value = 42;
string string;

stringstream ss; // 1st statement
ss << value; // 2nd statement
ss >> string; // 3rd statement

---

If you're doing Windows programming with MFC:

int value = 42;
CString string;

string.Format("%d", value); // 1 statement