#defining cout中的问题?

Arg*_* P. 0 c++

我的一个朋友告诉我这个代码有一些问题:

#include <iostream>
#include <cstdio>
using namespace std;
#define cout printf   
int main(){
    cout("cout");
}
Run Code Online (Sandbox Code Playgroud)

他没有告诉我原因,并让我弄清楚哪些我不能.代码似乎工作正常,它可能有什么问题?

Pra*_*rav 11

据我所知,标准禁止在任何标准库头中声明名称(使用#define).

在n3290($ 17.6.4.3.1)中找到了这个

17.6.4.3.1宏名[macro.names]

1包含标准库头的转换单元不得在任何标准库头中声明#define或#undef名称.

  • 换句话说,如果他删除了`#include <iostream>`行,他的程序将是合法的,只是令人困惑.截至目前,它甚至不需要编译. (2认同)