How to convert an int to a string?

May 29, 2012 at 2:13pm
I need to convert integers to strings. Can anyone tell me how would I go about doing this as I am very much stumped :(.
May 29, 2012 at 2:15pm
closed account (zb0S216C)
std::stringstream[1].

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


Wazzak
May 29, 2012 at 2:15pm
Last edited on May 29, 2012 at 2:16pm
May 29, 2012 at 2:24pm
May 29, 2012 at 3:20pm
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?
May 29, 2012 at 3:23pm
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/
May 29, 2012 at 3:23pm
It's more likely that your compiler isn't C++11 compliant.
May 29, 2012 at 3:25pm
I'm using Visual Studio 2008? And thank you Moooce I'll take a look now
May 29, 2012 at 3:32pm
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 May 29, 2012 at 3:33pm
May 29, 2012 at 3:36pm
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.