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

Im trying to modify the class below so that the scrolling text appears behind
I'm trying to modify the following code so that it will return a Dictionary<int,int>
I'm trying to modify some code that returns results from the database. Currently the
I am trying to modify this script to accept , - and ' for
I’m trying to modify a string of the following form where each field is
I have a nested function where I am trying to access variables assigned in
I am trying to modify an xml file from my aspx code. The file
I'm trying to modify an existing application using AWT for dialogs, etc. I don't
I'm trying to modify project.vim to open the project window on the right side
I am trying to get call log by using the CallLog.Calls content provider. However,

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.