Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How i could print n number of parameters of any data type to a debug?

I know of the WINAPI OutputDebugString(L"");

How I could go with a function able to receive n number of parameters which any data type, and print the value to a debug?

By debug I mean a window similar of the Visual Studio Output.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

This can be achieved with a template:

   #include <utility>
   #include <iomanip>
   #include <sstream>

    template <typename Arg, typename... Args>
    void Print(Arg&& arg, Args&&... args)
    {
        std::stringstream ss;
    
        ss<< std::forward<Arg>(arg);
        using expander = int[];
        (void)expander {
            0, (void(out << std::forward<Args>(args)), 0)...
        };
    
        OutputDebugStringA(ss.str().c_str());
    }
    
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    
        Print( 1, "abcde", 2, 3, "foo");
    }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading