空主 [英] Empty Main

查看:117
本文介绍了空主的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能告诉我如何显示Hello World吗?在C ++中没有

在main中写任何东西?ie,main不应该包含一个

单个语句(没有对象创建或没有cout或任何东西)

Could anyone tell me how to display "Hello World" in C++ without
writing anything inside main?i.e, main should not contain even a
single statement (no object creation or no cout or anything)

推荐答案

" Raj" < RA ******** @ gmail.com>在留言中写道

news:11 ********************** @ f14g2000cwb.googlegr oups.com ......

:有人能告诉我如何显示Hello World吗?在C ++中没有

:在main中写任何东西?ie,main不应该包含

:单个语句(没有对象创建或没有cout或任何东西)


您是否研究过构建/销毁全球

物品?

-
http://ivan.vecerina.com/contact/?subject=NG_POST < - 电子邮件联系表格

"Raj" <ra********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
: Could anyone tell me how to display "Hello World" in C++ without
: writing anything inside main?i.e, main should not contain even a
: single statement (no object creation or no cout or anything)

Have you studied the construction/destruction of global
objects yet ?
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form


请尝试以下方法:


#include< iostream>

使用命名空间std;


class t

{

public:

t(){std: :cout<<"" Hello world!"<< std :: endl; }

};


t _t;


int main()

{


}


这应该有效。

Try the following:

#include <iostream>
using namespace std;

class t
{
public:
t(){ std::cout<<"Hello world!"<<std::endl; }
};

t _t;

int main()
{

}

This should work.


"哈利" <公顷******* @ gmail.com>在消息新闻中写道:11 ******************** @ g14g2000cwa.googlegrou ps.com ...
"Harry" <ha*******@gmail.com> wrote in message news:11********************@g14g2000cwa.googlegrou ps.com...
请尝试以下方法:

#include< iostream>
使用命名空间std;

class t
{
公开:
t(){std :: cout<<"" Hello world!"<< std :: endl; }
};

t _t;

int main()
{

}
Try the following:

#include <iostream>
using namespace std;

class t
{
public:
t(){ std::cout<<"Hello world!"<<std::endl; }
};

t _t;

int main()
{

}

This should work.




如果看到这在某些平台上有效。

但是在其他平台上,它失败了,因为cout也是一个静态对象

和_t的构造函数在cout尚未构建时被调用。

在这种情况下我使用printf。


Fred.Zwarts。



If have seen that this works on some platforms.
On other platforms, however, it failed because cout is also a static object
and the constructor of _t was called when cout had not yet been constructed.
In such cases I use printf.

Fred.Zwarts.


这篇关于空主的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆