我通常使用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;
Run Code Online (Sandbox Code Playgroud)
我知道我可以使用格式化输出,cout但我已经知道如何使用printf.有什么理由我不应该使用这个printf陈述吗?