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

  • Home
  • SEARCH
  • 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 8006641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:34:48+00:00 2026-06-04T17:34:48+00:00

I currently have a logging system that takes a char* and var args and

  • 0

I currently have a logging system that takes a char* and var args and then uses them to do a printf. This works well with C-style strings, but I’d something that’s a little cleaner. Currently if I use std::stringstream I must create the stringstream outside of the logging system, and then use the char* to the string given by the stringstream. It looks something like this:

std::stringstream strStream;
strStream << "The value of x is: " << x;
logging::print( strStream.str().c_str() );

What I would like is to pass the paramaters into the function as if I was using them directly with a stringstream. Which would look something like this from the user’s point of view:

logging::printStream("The value of x is: " << x);

or possibly like this:

logging::printStream("The value of x is: ", x);

Is there any way to use logging in such a way that I can use a stringstream without having to create it outside of the logging system’s functions?

This is especially important because I intend to create a macro that prevents any of the function parameters from compiling in shipping builds. The macro will be useless if I have to create the stringstream outside of it and pass it in. Technically I could make a macro that does the stringstream stuff I’m talking about in this question, but that’s pretty messy as I won’t always be using stringstreams with this logging, so I would have a macro for the standard logging, and a different macro for using stringstreams that within it calls the macro for standard logging.

  • 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-06-04T17:34:50+00:00Added an answer on June 4, 2026 at 5:34 pm

    I came up with two HACK solutions, but they should work. The first doesn’t use the scope resolution operator and is safer. The second uses a noop int variable to fake out the scoping.

    #define logging_printStream(token) { std::stringstream o; o << token; logging::print(o.str().c_str()); }
    
    namespace logging { int noop; }
    #define printStream(token) noop = 0; { std::stringstream o; o << token; logging::print(o.str().c_str()); }
    
    int main(int argc, const char** argv)
    {
        int i = 1;
    
        // MORE SAFE
        logging_printStream(i)
        logging_printStream("is this magic? " << (i ? "yes" : "no"))
    
        // LESS SAFE
        logging::printStream(i)
        logging::printStream("is this magic? " << (i ? "yes" : "no"))
    }
    

    I updated logging__printStream to logging_printStream because of 17.6.4.3.2

    17.6.4.3.2 Global names [global.names]

    Certain sets of names and function signatures are always reserved to the implementation:

    • Each name that contains a double underscore _ _ or begins with an underscore followed by an uppercase letter (2.12) is reserved to the implementation for any use.
    • Each name that begins with an underscore is reserved to the implementation for use as a name in the global namespace.

    I left the declaration of main alone because of 3.6.1

    3.6.1 Main function [basic.start.main]

    A program shall contain a global function called main, which is the designated start of the program. It is implementation-defined whether a program in a freestanding environment is required to define a main function. An implementation shall not predefine the main function. This function shall not be overloaded. It shall have a return type of type int, but otherwise its type is implementation-defined.

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

Sidebar

Related Questions

I have a Java web application that currently uses Log4J for logging. I'd like
I currently have a project that uses Entity Framework 4.1 for logging to a
I currently have a query that looks like this: SELECT NON EMPTY ([Measures].[TOTAL]) ON
I currently have a UINavigationController based application that works just fine. I'd like to
I currently have a custom log manager that internally uses java.util.Formatter . The main
I have a simple ticket logging application build on LAMP. I am currently playing
I currently have links w/ class=ajax that I want to retrieve the element with
I currently have the dynamic array: char *myData[500][10]; //myData is the name of an
I have a C# web forms ASP.NET 4.0 web application that uses Routing for
Currently I have a custom form login page in Spring Security 3 that sends

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.