在 C# 中使用“cout”,如“Console.WriteLine”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11575923/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Use "cout" like "Console.WriteLine" in C#
提问by ForEveR
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:
在 C# 中你会写:
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
?
就像printf
在 C# 中一样,但我不想在我的程序中使用 C 语句;有没有办法<<
在不使用 C++ 的情况下编写更少的代码printf
?
回答by ForEveR
Use boost::format
for example.
boost::format
例如使用。
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);
所以在 C# 中它是 Console.WriteLine("statement A: {0}\t...", a, b, c, d);