user2108296
user2108296

Reputation:

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

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?

Upvotes: 3

Views: 46140

Answers (1)

ForEveR
ForEveR

Reputation: 55887

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);

Upvotes: 5

Related Questions