1、有以下C++代码:
- int main()
- {
- cout<<"hello world!\n";
- return 0;
- }
请不对main()函数做任何修改,程序运行后能输出:
"EMC"
"hello world!"
"exit"
答案1:
- struct B
- {
- ostream& operator << (const char*)
- {
- return (cout <<"EMC\n"
- "hello world!\n"
- "exit\n" );
- }
- }bbb;
- #define cout bbb
- int main()
- {
- cout<<"hello world!\n";
- return 0;
- }
答案2:
- using std::ostream;
- using std::cout;
- ostream& operator<<(ostream& io, const char (&szStr)[14])
- {
- printf ("EMC\n");
- printf (szStr);
- printf ("exit\n");
- return io;
- }
- int main()
- {
- cout<<"hello world!\n";
- return 0;
- }
以上答案是群里一位朋友做的,我算是学习了。
阅读(1615) | 评论(0) | 转发(0) |