How to convert an int to a string in C++? (Also doubles, floats, etc…)
Here is how I do it. This procedure actually works for any type such as: int, double, float, etc…
Convert an Int Only
#include
#include
#include
using namespace std;
int main()
{
int i = 10;
string s = inToString(i);
return 0;
}
string intToString(int inInt)
{
stringstream ss;
string s;
ss << inInt;
s = ss.str();
return s;
}
[/sourcecode]
As a Template So It Works with All Types (int, float, double, etc…)
I found a comment on another guys blog that actually makes it work for any type such as double, float, etc.. It has this code using this template.
http://notfaq.wordpress.com/2006/08/30/c-convert-int-to-string/
template
string anyTypeToString(const T& t)
{
std::stringstream ss;
ss << t;
return ss.str();
}
[/sourcecode]
This works really well, I have been using it and it is so simple.
Key words:
int to string
intToString
double to string
doublToString
float to string
floatToString
[...] double, etc) October 23, 2009, 9:36 pm by Rhyous Tweet Ok, so I already have a post on How to convert an int to a string in C++? (Also doubles, floats, etc…) and so I need a post on doing this in [...]
[...] How to convert an int to a character array when you don’t have access to the C++ Standard Library? Filed under: Coding — rhyous @ 3:44 am Ok, so I have a great way to convert and int (or any other type) to a string using the stringstream from the standard library. This is listed here: How to convert an int to a string in C++? (Also doubles, floats, etc…) [...]
[...] How to convert an int to a character array when you don’t have access to the C++ Standard Library? Filed under: Coding — rhyous @ 3:44 am Ok, so I have a great way to convert and int (or any other type) to a string using the stringstream from the standard library. This is listed here: How to convert an int to a string in C++? (Also doubles, floats, etc…) [...]
[...] How to convert an int to a character array when you don’t have access to the C++ Standard Library? Filed under: Coding — rhyous @ 3:44 am Ok, so I have a great way to convert and int (or any other type) to a string using the stringstream from the standard library. This is listed here: How to convert an int to a string in C++? (Also doubles, floats, etc…) [...]
[...] How to convert an int to a character array when you don’t have access to the C++ Standard Library? Filed under: Coding — rhyous @ 3:44 am Ok, so I have a great way to convert and int (or any other type) to a string using the stringstream from the standard library. This is listed here: How to convert an int to a string in C++? (Also doubles, floats, etc…) [...]
[...] How to convert an int to a character array when you don’t have access to the C++ Standard Library? Filed under: Coding — rhyous @ 3:44 am Ok, so I have a great way to convert and int (or any other type) to a string using the stringstream from the standard library. This is listed here: How to convert an int to a string in C++? (Also doubles, floats, etc…) [...]
[...] How to convert an int to a character array when you don’t have access to the C++ Standard Library? Filed under: Coding — rhyous @ 3:44 am Ok, so I have a great way to convert and int (or any other type) to a string using the stringstream from the standard library. This is listed here: How to convert an int to a string in C++? (Also doubles, floats, etc…) [...]
[...] How to convert an int to a character array when you don’t have access to the C++ Standard Library? Filed under: Coding — rhyous @ 3:44 am Ok, so I have a great way to convert and int (or any other type) to a string using the stringstream from the standard library. This is listed here: How to convert an int to a string in C++? (Also doubles, floats, etc…) [...]
[...] How to convert an int to a character array when you don’t have access to the C++ Standard Library? Filed under: Coding — rhyous @ 3:44 am Ok, so I have a great way to convert and int (or any other type) to a string using the stringstream from the standard library. This is listed here: How to convert an int to a string in C++? (Also doubles, floats, etc…) [...]
[...] How to convert an int to a character array when you don’t have access to the C++ Standard Library? Filed under: Coding — rhyous @ 3:44 am Ok, so I have a great way to convert and int (or any other type) to a string using the stringstream from the standard library. This is listed here: How to convert an int to a string in C++? (Also doubles, floats, etc…) [...]
[...] How to convert an int to a character array when you don’t have access to the C++ Standard Library? Filed under: Coding — rhyous @ 3:44 am Ok, so I have a great way to convert and int (or any other type) to a string using the stringstream from the standard library. This is listed here: How to convert an int to a string in C++? (Also doubles, floats, etc…) [...]
[...] How to convert an int to a character array when you don’t have access to the C++ Standard Library? Filed under: Coding — rhyous @ 3:44 am Ok, so I have a great way to convert and int (or any other type) to a string using the stringstream from the standard library. This is listed here: How to convert an int to a string in C++? (Also doubles, floats, etc…) [...]
[...] How to convert an int to a character array when you don’t have access to the C++ Standard Library? Filed under: Coding — rhyous @ 3:44 am Ok, so I have a great way to convert and int (or any other type) to a string using the stringstream from the standard library. This is listed here: How to convert an int to a string in C++? (Also doubles, floats, etc…) [...]
[...] How to convert an int to a character array when you don’t have access to the C++ Standard Library? Filed under: Coding — rhyous @ 3:44 am Ok, so I have a great way to convert and int (or any other type) to a string using the stringstream from the standard library. This is listed here: How to convert an int to a string in C++? (Also doubles, floats, etc…) [...]
[...] How to convert an int to a character array when you don’t have access to the C++ Standard Library? Filed under: Coding — rhyous @ 3:44 am Ok, so I have a great way to convert and int (or any other type) to a string using the stringstream from the standard library. This is listed here: How to convert an int to a string in C++? (Also doubles, floats, etc…) [...]
[...] How to convert an int to a character array when you don’t have access to the C++ Standard Library? Filed under: Coding — rhyous @ 3:44 am Ok, so I have a great way to convert and int (or any other type) to a string using the stringstream from the standard library. This is listed here: How to convert an int to a string in C++? (Also doubles, floats, etc…) [...]
[...] How to convert an int to a character array when you don’t have access to the C++ Standard Library? Filed under: Coding — rhyous @ 3:44 am Ok, so I have a great way to convert and int (or any other type) to a string using the stringstream from the standard library. This is listed here: How to convert an int to a string in C++? (Also doubles, floats, etc…) [...]
[...] How to convert an int to a character array when you don’t have access to the C++ Standard Library? Filed under: Coding — rhyous @ 3:44 am Ok, so I have a great way to convert and int (or any other type) to a string using the stringstream from the standard library. This is listed here: How to convert an int to a string in C++? (Also doubles, floats, etc…) [...]
[...] double, etc) Filed under: Coding — rhyous @ 9:36 pm Ok, so I already have a post on How to convert an int to a string in C++? (Also doubles, floats, etc…) and so I need a post on doing this in [...]
[...] double, etc) Filed under: Coding — rhyous @ 9:36 pm Ok, so I already have a post on How to convert an int to a string in C++? (Also doubles, floats, etc…) and so I need a post on doing this in [...]
[...] double, etc) Filed under: Coding — rhyous @ 9:36 pm Ok, so I already have a post on How to convert an int to a string in C++? (Also doubles, floats, etc…) and so I need a post on doing this in [...]
[...] double, etc) Filed under: Coding — rhyous @ 9:36 pm Ok, so I already have a post on How to convert an int to a string in C++? (Also doubles, floats, etc…) and so I need a post on doing this in [...]
[...] double, etc) Filed under: Coding — rhyous @ 9:36 pm Ok, so I already have a post on How to convert an int to a string in C++? (Also doubles, floats, etc…) and so I need a post on doing this in [...]
[...] double, etc) Filed under: Coding — rhyous @ 9:36 pm Ok, so I already have a post on How to convert an int to a string in C++? (Also doubles, floats, etc…) and so I need a post on doing this in [...]
[...] double, etc) Filed under: Coding — rhyous @ 9:36 pm Ok, so I already have a post on How to convert an int to a string in C++? (Also doubles, floats, etc…) and so I need a post on doing this in [...]
[...] double, etc) Filed under: Coding — rhyous @ 9:36 pm Ok, so I already have a post on How to convert an int to a string in C++? (Also doubles, floats, etc…) and so I need a post on doing this in [...]
[...] double, etc) Filed under: Coding — rhyous @ 9:36 pm Ok, so I already have a post on How to convert an int to a string in C++? (Also doubles, floats, etc…) and so I need a post on doing this in [...]
[...] double, etc) Filed under: Coding — rhyous @ 9:36 pm Ok, so I already have a post on How to convert an int to a string in C++? (Also doubles, floats, etc…) and so I need a post on doing this in [...]
[...] double, etc) Filed under: Coding — rhyous @ 9:36 pm Ok, so I already have a post on How to convert an int to a string in C++? (Also doubles, floats, etc…) and so I need a post on doing this in [...]
[...] double, etc) Filed under: Coding — rhyous @ 9:36 pm Ok, so I already have a post on How to convert an int to a string in C++? (Also doubles, floats, etc…) and so I need a post on doing this in [...]
[...] double, etc) Filed under: Coding — rhyous @ 9:36 pm Ok, so I already have a post on How to convert an int to a string in C++? (Also doubles, floats, etc…) and so I need a post on doing this in [...]
[...] double, etc) Filed under: Coding — rhyous @ 9:36 pm Ok, so I already have a post on How to convert an int to a string in C++? (Also doubles, floats, etc…) and so I need a post on doing this in [...]
[...] double, etc) Filed under: Coding — rhyous @ 9:36 pm Ok, so I already have a post on How to convert an int to a string in C++? (Also doubles, floats, etc…) and so I need a post on doing this in [...]
[...] double, etc) Filed under: Coding — rhyous @ 9:36 pm Ok, so I already have a post on How to convert an int to a string in C++? (Also doubles, floats, etc…) and so I need a post on doing this in [...]
[...] double, etc) Filed under: Coding — rhyous @ 9:36 pm Ok, so I already have a post on How to convert an int to a string in C++? (Also doubles, floats, etc…) and so I need a post on doing this in [...]