I am trying to modify my log class to accept variables in my string. For example, if I wanted to output that there are 7 players in an area.
Here is my write to log function:
void Log::writeSuccess(string text,...)
{
// Write the sucessfull operation to the logfile
logfile << "<---> " << text << endl;
}
And here is my calling code:
int playernum = 7;
errorLog.writeSuccess("There are %i players in the area", playernum);
It just ends up outputting to the file: There are %i players in the area
Any way to fix this?
In case you can’t or won’t use boost:
Note: it assumes that the written length is limited.
Update: with gcc it’s possible to do this in a type-safe way, you need the following declaration.
Info here. Note: it’s a warning, not a compile error. If you ignore warnings that’s your problem..:)