你好世界节目 [英] hello world program

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

问题描述

大家好,

我正在尝试运行小程序helloworld.cpp。

但是我没有在stdout上获得任何输出


计划是

#include< iostream.h>

main(){

cout<< hello world;

}

>>>> ;>>>>>>>>>>>>>>>>>>


#include< iostream>

使用命名空间std;

main(){

cout<<" hello world" ;;

}


我用g ++编译程序
g ++ helloworld.cpp -o helloworld

../helloworld


它在stdout打印hello world


我正在使用的编译器是

gcc版本3.2 20020903(Red Hat Linux 8.0 3.2-7)

解决方案

On Thu,2003年8月28日23:04:03 -0700,Rahul Gandhi写道:

大家好,
我正在尝试运行小程序helloworld。 cpp。
但是我没有在stdout上获得任何输出

程序是
#include< iostream.h>
main(){
cout<<" hello world";
}

>>>>>>> >>>>>>>>>>>>>>>>>>>>


#include< iostream>
使用命名空间std;
main(){
cout<<" hello world" ;;
}
我用g ++编译了程序
g ++ helloworld.cpp -o helloworld
./helloworld

它确实在stdout上打印了hello world

我正在使用的编译器是
gcc版本3.2 20020903(Red Hat Linux 8.0 3.2-7)




我正在使用

gcc版本3.2.2 20030 222(Red Hat Linux 3.2.2-5)

并且两个版本都编译并打印到stdout,虽然第一个给出了

警告,iostream.h似乎是 ;陈旧的" ;.

也许你只是忽略它,因为它在下一个提示之前。

在世界之后插入\ n。


-

mfg

Volker Mosthaf


" Jim Fischer" < JF *************** @ now.here.com>在消息中写道

news:01 ***************** @ fe01.atl2.webusenet.com ..

|我不知道这是不是问题,但试着冲洗输出

|程序结束前流''cout':


是的,这很可能就是问题所在。你还应该使main()int main()

并在结束时返回0(在关闭大括号之前):


#include< iostream>


int main()

{

std :: cout<< Hello Rahul Gandhi! << std :: flush;

return(0);

}


Greg P.写道:

Jim Fischer < JF *************** @ now.here.com>在消息中写道
新闻:01 ***************** @ fe01.atl2.webusenet.com ..。

我不知道知道这是不是问题,但在程序结束前尝试刷新输出流''cout':
是的,这很可能就是问题所在。你还应该使main()int
main()并在结束时返回0(在关闭大括号之前):

#include< iostream>

int main()
{
std :: cout<< Hello Rahul Gandhi! << std :: flush;




这可能仍然无效,没有新行。你可以冲洗它但

显示只能保证线路。所以游戏是:


std :: cout<< Hello Rahul Gandhi! << std :: endl;


std :: endl向缓冲区发送换行符然后确保写入

(执行std :: flush) 。

return(0);


不需要。即使你写它也绝对没有必要使用围绕0的括号。

}




-

Attila aka WW


Hi guys,
I''m trying to run small program helloworld.cpp.
But i''m not getting any output on the stdout

program is
#include<iostream.h>
main(){
cout<<"hello world";
}

>>>>>>>>>>>>>>>>>>>>>>


#include<iostream>
using namespace std;
main(){
cout<<"hello world";
}

I have compiled the program with g++
g++ helloworld.cpp -o helloworld
../helloworld

It does prints hello world on stdout

compiler I''m using is
gcc version 3.2 20020903 (Red Hat Linux 8.0 3.2-7)

解决方案

On Thu, 28 Aug 2003 23:04:03 -0700, Rahul Gandhi wrote:

Hi guys,
I''m trying to run small program helloworld.cpp.
But i''m not getting any output on the stdout

program is
#include<iostream.h>
main(){
cout<<"hello world";
}

>>>>>>>>>>>>>>>>>>>>>>>


#include<iostream>
using namespace std;
main(){
cout<<"hello world";
}

I have compiled the program with g++
g++ helloworld.cpp -o helloworld
./helloworld

It does prints hello world on stdout

compiler I''m using is
gcc version 3.2 20020903 (Red Hat Linux 8.0 3.2-7)



I am using
gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
and both versions compile and print to stdout, although the first gives a
warning ,iostream.h seems to be "antiquated".
Maybe You just overlooked it, because its in front of the next prompt.
Insert \n after world.

--
mfg
Volker Mosthaf


"Jim Fischer" <jf***************@now.here.com> wrote in message
news:01*****************@fe01.atl2.webusenet.com.. .
| I don''t know if this is the problem or not, but try flushing the output
| stream ''cout'' before the program ends:

Yes, this is most likely the problem. You should also make main() int main()
and return 0 at the end (before closing brace):

#include <iostream>

int main()
{
std::cout << "Hello Rahul Gandhi!" << std::flush;
return(0);
}


Greg P. wrote:

"Jim Fischer" <jf***************@now.here.com> wrote in message
news:01*****************@fe01.atl2.webusenet.com.. .

I don''t know if this is the problem or not, but try flushing the
output stream ''cout'' before the program ends:
Yes, this is most likely the problem. You should also make main() int
main() and return 0 at the end (before closing brace):

#include <iostream>

int main()
{
std::cout << "Hello Rahul Gandhi!" << std::flush;



This may still not work, there is no newline. You may flush it but
displaying is only guaranteed for lines. So the game is:

std::cout << "Hello Rahul Gandhi!" << std::endl;

std::endl sends a newline to the buffer and then make sure it is written
(does an std::flush).
return(0);
No need for that. And even if you write it there is absolutely no need for
the parentheses around the 0.
}



--
Attila aka WW


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

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