How to convert an int to a string?

I need to convert integers to strings. Can anyone tell me how would I go about doing this as I am very much stumped :(.
closed account (zb0S216C)
std::stringstream[1].

References:
[1]http://www.cplusplus.com/reference/iostream/stringstream/


Wazzak
Last edited on
Peter 87 I tried to use std::to_string but got the error: "to string is not a member of std". Am I missing a header? I have included:

#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cmath>

but I'm guess std has something to do with the namespace?

Can anyone clarify this for me?
Depends on the age of your compiler.
If you're using VS2005 or something similar take a look at how I did it here

http://www.cplusplus.com/forum/beginner/70780/
It's more likely that your compiler isn't C++11 compliant.
I'm using Visual Studio 2008? And thank you Moooce I'll take a look now
Here's a page of resources regarding which compilers support C++11 and the like.

http://www.aristeia.com/C++11/C++11FeatureAvailability.htm

The apache wiki makes it particularly easy to have a quick glance: http://wiki.apache.org/stdcxx/C++0xCompilerSupport

Last edited on
The most funny that the MS VC++ 2010 contains a bug and if you will use std::to_string for a object of type int your code will not be compiled.:)
Topic archived. No new replies allowed.