Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6200443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:22:10+00:00 2026-05-24T04:22:10+00:00

I am trying to modify my log class to accept variables in my string.

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T04:22:11+00:00Added an answer on May 24, 2026 at 4:22 am

    In case you can’t or won’t use boost:

    void Log::writeSuccess(const char* const fmt, ...) {
        va_list ap;
        va_start(ap, fmt);
        char buff[1024];
        vsnprintf(buff, sizeof(buff), fmt, ap);
        logfile << buff;
    }
    

    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.

    class Log {
        void writeSuccess(const char* const fmt, ...) __attribute__ ((format (printf, 2, 3)));
        //...
    };
    

    Info here. Note: it’s a warning, not a compile error. If you ignore warnings that’s your problem..:)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to modify the class of an element if an ajax call based
I am trying to modify the output stream to search/replace some XHTML tags returned
Hi I'm trying to modify a web page so that it loads faster. Since
I am trying to modify the amcap, an application from Windows SDK's example to
I've been trying to modify the AuditTrail code so that it does not copy
I'm trying to modify the various loaders out there so multiple scripts can be
I am trying to find a good example that can help me to understand
I'm trying to modify the vestal_versions plugin to accept a parameter I set upon
I'm trying to use a raphael.js example located here: http://raphaeljs.com/pie.html but I want to
I'm trying to modify a plugin so that image files from a directory can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.