我通常使用 cout
和 cerr
将文本写入控制台。但是有时候我发现使用旧的 printf
语句更容易。我在需要格式化输出时使用它。
我会在哪里使用这个例子:
// Lets assume that I'm printing coordinates...
printf("(%d,%d)\n", x, y);
// To do the same thing as above using cout....
cout << "(" << x << "," << y << ")" << endl;
我知道我可以格式化输出使用 cout
,但我已经知道如何使用 printf
。有什么理由我不应该使用 printf
语句吗?