looking for an int to string converter
I looked in the visual c++ help file and couldn''t find one, I need a function that can turn a long unsigned int into a char string.
Bloodshed Dev-C++ 4.9.8.0
DX 9.0a DX SDK 6.1
win98
#define WIN32_LEAN_AND_MEAN
the Particle Projection Cannon fires a shimmering blue bolt, much like a cross between lightning and a sine wave that ripples along its path.
look up sprintf:
you could always then load the buffer into a std::string and truncate it to make it as short as possible.
-me
int foo = 1000;char buffer[256];sprintf(buffer, "%d", foo);
you could always then load the buffer into a std::string and truncate it to make it as short as possible.
-me
The C++ way to do this (sprintf is C) is to use ostringstream.
Kami no Itte ga ore ni zettai naru!
[edited by - tangentz on February 19, 2004 7:23:53 PM]
#include <sstream>using namespace std;int i = 10;ostringstream oss;string s;oss << i;s = oss.str();
Kami no Itte ga ore ni zettai naru!
[edited by - tangentz on February 19, 2004 7:23:53 PM]
quote:Original post by SiCrane
I''m suprised no one has suggested boost::lexical_cast<> yet.
Last time I checked lexical_cast (that would be 30 seconds ago),
it''s just a fancier wrapper around stringstream.
Kami no Itte ga ore ni zettai naru!
True, but using a lexical_cast can protect you from certain bugs. For example, about a week and a half ago, a forum poster was having trouble using a stringstream method because he was reusing the stringstream object and the eof bit was being set after extraction, causing subsequent uses of the stringstream object to fail.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement