Use "cout" like "Console.WriteLine" in C#

38,344

Use boost::format for example.

cout << boost::format("statement A: %1%\tstatement B: %2%\tstatement C: %3%\t statement D: %4%") %a %b %c %d << endl;

So in C# it was Console.WriteLine("statement A: {0}\t...", a, b, c, d);

Share:
38,344
Admin
Author by

Admin

Updated on July 20, 2020

Comments

  • Admin
    Admin almost 4 years

    Imagine there are many statement and messages to write out on the screen

    cout << "statement A :" << a << "\t statement B :" << B
         << "\t statement C :" << C << "\t statement D :" << D;
    

    in C# you’d write:

    Console.WriteLine(
        "statement A :{0}\t statement B :{1}\t statement C :{2}\t statement D :{3}",
        a, b, c, d);
    

    it is like printf in C# but I don’t want to use C statements in my program; is there a way to write fewer << in C++ without using printf?