写一个程序,将打印" C"如果编译为(ANSI)C程序,并与QUOT; C ++"如果编译为C ++程序 [英] Write a program that will print "C" if compiled as an (ANSI) C program, and "C++" if compiled as a C++ program
本文介绍了写一个程序,将打印" C"如果编译为(ANSI)C程序,并与QUOT; C ++"如果编译为C ++程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从<一个拍摄href=\"http://www.ocf.berkeley.edu/~wwu/riddles/cs.shtml\">http://www.ocf.berkeley.edu/~wwu/riddles/cs.shtml
看起来非常具体的编译器给我。不知道去哪里找呢?
It looks very compiler specific to me. Don't know where to look for?
推荐答案
就这么简单。
#include <stdio.h>
int main(int argc, char ** argv) {
#ifdef __cplusplus
printf("C++\n");
#else
printf("C\n");
#endif
return 0;
}
还是有这样做没有官方标准的要求?
Or is there a requirement to do this without the official standard?
这篇关于写一个程序,将打印&QUOT; C&QUOT;如果编译为(ANSI)C程序,并与QUOT; C ++&QUOT;如果编译为C ++程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文