First of all, I apologize if the title is misleading, I don't really know how to describe what I want to do in one line . I am working on a text console game. I am having some trouble implementing the combat messages. For those of you who have played any RPG games before you would have a good idea what the combat message window looks like. If not, here is a little explainations, I intend to have 4 lines of combat messages showing on the screen, the newest message would be pushed in at the bottom of the combat message box and effectively popping out the oldest message on the top. I think I know how to do that, I'll simply have 4 pointers and I will shift them up by one and have the pointer representing the newest line point to the new message string. So I am going to have a function that looks like
void DrawCombatMsg(char *text);
The argument would be the latest combat message, I don't know if passing it a cstring is the best way to do it but when I experimented with passing it a string class my compiler failed to recognize the function prototype in the header file It whined something about the identifier not found.
But before I pass the latest combat message to my DrawCombatMsg() function I need to formulate the string (name of attacker, name of defender, hit or miss, how much damage). I have another function called
for that. Now this is where I am really confused. What kind of argument and return type should I put for FormCombat Msg function? Ideally I want it to return a string but the only way I know how to "form"(where I combine variables and strings) a string is by using cout and that that puts it directly to the standard output. So I guess my question is, is there a way that I can format a string and "save" it to another string so I can use it later on as an argument?
I experimented with the string class of the string library and ostringstream of the sstream library, none of them really worked for me, most likely because I didn't use them right. Please help.