Interger converted to String
Hi, I am working on a SDL game engine and it is going very well, except one problem. I caculate my frames per second and want to convert it to a string to send to my text print out function which accepts a string for the message. I know how to convert it into a int to a char but I want to convert a int to a string.
Hope you understand, can anyone help?
What language? I''ll assume C (ISO).
int Integer = 12345;char String[12];snprintf(String,12,"%d",Integer);
C++
I knew about that but what about something like
int Integer = 12345;
string strInteger;
snprintf(strInteger,"%d",Integer);
I dont wanna use char bla[12], instead I was to use a string. (Yes I know strings are all chars at heart but I want a string object not a char array, kinda the same thing but I hope it makes some sense.)
I knew about that but what about something like
int Integer = 12345;
string strInteger;
snprintf(strInteger,"%d",Integer);
I dont wanna use char bla[12], instead I was to use a string. (Yes I know strings are all chars at heart but I want a string object not a char array, kinda the same thing but I hope it makes some sense.)
How about the following:
------
Check a Reseller's Rating Before You Purchase!
[edited by - aNonamuss on April 23, 2002 11:04:01 PM]
int main(int argc, char *argv[]){ int iValue; char szTempString[1000]; // fill iValue with an integer, frame rate, value . . . string testing(itoa(iValue, szTempString, 10)); cout << testing; return 0;}
------
Check a Reseller's Rating Before You Purchase!
[edited by - aNonamuss on April 23, 2002 11:04:01 PM]
quote:Original post by Tszafran
Hi, I am working on a SDL game engine and it is going very well, except one problem. I caculate my frames per second and want to convert it to a string to send to my text print out function which accepts a string for the message. I know how to convert it into a int to a char but I want to convert a int to a string.
Hope you understand, can anyone help?
C++ - Use stringstream
string getFPS(){//calculate fps in variable frames stringstream input; input<<frames; return input.str();}
Why make it simple when you can make it sooo nice and complicated?
C++, using the Boost library.
You write it out just like any other C++ cast.
[Questions (STFW) | GDNet Start Here | GDNet Search | Forum FAQ | Google | Asking Smart Questions ]
[Docs (RTFM) | MSDN | SGI''s STL | OpenGL | File formats]
[C++ Must Haves (RTFS) | MinGW | Boost | Loki | FLTK | SDL ]
Stolen from Magmai Kai Holmlor, who held it from Oluseyi, who was inspired by Kylotan...
#include <lexical_cast.hpp>std::string myString = "12345";int myInt = boost::lexical_cast<int>( myString );
You write it out just like any other C++ cast.
[Questions (STFW) | GDNet Start Here | GDNet Search | Forum FAQ | Google | Asking Smart Questions ]
[Docs (RTFM) | MSDN | SGI''s STL | OpenGL | File formats]
[C++ Must Haves (RTFS) | MinGW | Boost | Loki | FLTK | SDL ]
Stolen from Magmai Kai Holmlor, who held it from Oluseyi, who was inspired by Kylotan...
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement