Sign in to follow this  
mako_5

C++ Strings

Recommended Posts

I've found some information on appending to strings in C++ but nothing about how to add another type of data field (i.e. unsigned int) to a string. Is there a conversion method or something? (i'm still migrating over from Java) I'm trying to get a const char* to display text on screen using Irrlicht. The problem is how do I append an integer to a char*. What I'm trying to do is display a character's name followed by their HP/MP int values, but don't know how to dynamically build the display string. The display string would equal : character name + HP + MP

Share this post


Link to post
Share on other sites
EDIT: John wins. ;) That's what I get for sitting here doublechecking in VC++. :P

For std::strings, std::stringstreams are good:


#include <sstream>

std::stringstream s;
s << "You have " << hp << " HP and " << mp << "MP";


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this