韩老师的题:在不改动main()函数的情况下,
如何修改以下代码,使其输出 begin hello world end
|
发现有几种实现方法:
1:#include<iostream>
#include<cstdio>
using namespace std;
class A
{
public:
A()
{
cout<<"begin"<<endl;
}
~A()
{
printf("end/n");
}
};
A a;
int main()
{
cout<<"hello world"<<endl;
}
2:
#include <iostream>
#define cout cout
#define cout cout<<"begin/n"
#define endl "/nend/n"
using namespace std;
void main()
{
cout<<"hello world"<<endl;
}
#define cout cout
#define cout cout<<"begin/n"
#define endl "/nend/n"
using namespace std;
void main()
{
cout<<"hello world"<<endl;
}