在C#中使用"cout",如"Console.WriteLine"

2 c++ printf cout

想象一下,屏幕上会写出许多声明和消息

cout << "statement A :" << a << "\t statement B :" << B
     << "\t statement C :" << C << "\t statement D :" << D;
Run Code Online (Sandbox Code Playgroud)

在C#你写的:

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

它就像printf在C#中,但我不想在我的程序中使用C语句; 有没有办法<<在不使用C++的情况下编写更少的东西printf

For*_*veR 5

boost::format例如.

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

所以在C#中它是 Console.WriteLine("statement A: {0}\t...", a, b, c, d);

  • @ user1521362你应该拥抱Boost.如果您正在编写C++,那么在没有使用Boost的情况下,您无法在大型项目中编写好的代码. (2认同)