首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

添加代码,该怎么解决

2012-03-15 
添加代码#include stdio.h#include iostreamusing namespace std//只在此添加一行代码*void main(){c

添加代码

#include "stdio.h"
#include <iostream>
using namespace std;

//只在此添加一行代码
*
void main()
{
cout<<"WORLD"<<endl;
}

void Func()
{
cout<<"HELLO"<<endl;
}

上面的代码中怎样只在*处添加一行代码就能输出Func()中的内容。

[解决办法]
#define cout cout<<"HELLO"<<endl
[解决办法]
1. 声明Func 
2. 重载<<运算符
3. 利用全局变量防止无休止的递归调用

C/C++ code
void Func(); int invokeCnt=0; ostream& operator << (ostream& out, const char* p) { if (++invokeCnt < 2) Func(); string str = p; return out<<str; }
[解决办法]
只加一行的话就顶1楼了
如果还想别的办法,可以去这里看看
http://student.csdn.net/space.php?uid=236414&do=blog&id=23295
[解决办法]
#define main Func(void);void main(){Func();}void Func1

热点排行