SRL Archive - C/C++ Help and Tutorials

Need help with my Hello World app.


Ron

2007-03-01 11:47:23

Need help with my Hello World app. I'm using the Dev C++ compiler.


#include <iostream.h>
int main()
{
cout << "Hello World!";
system("Pause");
return 0;
}

What am I doing wrong? The only thing that shows up is command prompt paused. But it doesn't output "Hello World!". Why is that? I also tried using printf instead of cout, but I got the same result.

Thanks for the help.

JAD

2007-03-01 11:58:15

try this:

program New;
begin
Writeln('Hello world');
end.
lol, thats easier then C++ if you ask me :p

omgh4x0rz

2007-03-01 12:14:58

Lol. Jad, he is writing in C++, not anything to do with scar!

Ron, try doing this.

cout << "Hello World!"<<endl;

JAD

2007-03-01 13:20:13

From: omgh4x0rz
Lol. Jad, he is writing in C++, not anything to do with scar!

Ron, try doing this.

cout << "Hello World!"<<endl;


Lol i knew that :p I know what C++ is, just don't know how to write it :p

Ron

2007-03-03 11:27:46

This code seems to work properly. I just need a way to output information like Hello World, and it seems to work for everyone else but me.


#include <windows.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
MessageBox(NULL, "Yeeaaaaaaahhhhh!", "Yay!", MB_OK);
return 0;
}

The code is not the problem. I'm guessing I have to check some setting or something to get this work. Because it does compile successfully, it just doesn't seem to know what window to output to, or I just don't know which window it is outputting to.

KuJi

2007-03-03 12:10:13

From: Ron
Need help with my Hello World app. I'm using the Dev C++ compiler.


#include <iostream.h>
int main()
{
cout << "Hello World!";
system("Pause");
return 0;
}

What am I doing wrong? The only thing that shows up is command prompt paused. But it doesn't output "Hello World!". Why is that? I also tried using printf instead of cout, but I got the same result.

Thanks for the help.


You may need to use using namespace std; or std::cout

EX:


#include <iostream.h>
using namespace std;

int main()
{
cout << "Hello World!";
system("Pause");
return 0;
}

OR


#include <iostream.h>

int main()
{
std::cout << "Hello World!";
system("Pause");
return 0;
}

I would try it, but I no longer have MSVC++ 2005 nor Dev-CPP since I just reformatted. Sorry. ( should work though )

Ron

2007-03-03 16:40:30

:( Same problem. Thanks any way KuJi.

omgh4x0rz

2007-03-06 15:40:33

Unless you have this <<endl; closing off "hello world", then it will appear on the same line as "press any key to continue" maybe you just looked quickly and didn't see it?

Smartzkid

2007-03-06 15:44:03

I think it's one of your settings; I'm using Bloodshed Dev-C++ (v4.9.9.2), and it worked fine. And it does print everything on one line…

#include <iostream.h>
int main()
{
cout << "Hello World!" <<endl;
system("Pause");
return 0;
}

EDIT: yay 400th post :p

c0de

2007-03-06 16:58:45

Ron, does your command prompt close after you execute program?

If so, you have to start command prompt by going to Start -> Run
then type:
1. If you're on w98 -> command
2. if you're on w2k-wXP -> cmd

then go to your directory, compile program and execute it.

Let's say your compiler is cc.exe and you have it's directory in your global path, then you do cc program.cpp

it outputs program.exe
now just type program or program.exe and it should execute and give you output without closing command prompt ;-)

thiefmn6092

2007-03-07 14:27:42

cout shouldn't have even worked unless namespace std was used,


#include <cstdlib>
#include <iostream>

You'll need too have those two defined and

using namespace std;

hakeris15

2007-03-25 05:32:40

you are starter with c++ ?

marneus901

2007-03-25 15:27:39

Unless you have this <<endl; closing off "hello world", then it will appear on the same line as "press any key to continue" maybe you just looked quickly and didn't see it?

The press any key to continure is in java, not c++, now you do need the system("Pause"); otherwise (as i remember my first week into c++), it will just close automatically, or try makking an input


#include <cstdlib>
#include <iostream>

int main()
{
char um2[5]={'I', 'L', 'U', 'V', 'U'};
int num=0;
for(int counter=0; counter<5; counter++)
{
if (counter==1)
{
cout << " ";
}
cout << um2[counter];
}
cout <<"\nEnter a number plz : ";
cin >> num;
}

the using namespace std
and including the << endl;, but after all that i forget, its been a year sense ive used c++, ive been using java
lol
system.out.println("Java alot easier for me then c++, lol\n\n\n");

duther

2007-04-20 19:25:14

The program is closing just after being ran because there's nothing to stop it from doing that.
You have two easy options:
The first is doing a system("pause"). Note that this function is windows only. It is either accessible by default or in stdlib.h.
The second option, is using a function such as getch().


About namespaces (std)

The C++ standard now says that the standard library has to be wrapped into a namespace called std. A few years ago, it wasn't. Back then, a hello world would be:

#include <iostream.h>
int main(void) { cout << "hello"; system("pause"); return 0; }

In modern compilers, however, this WILL NOT compile, because <iostream.h> is outdated, and isn't even included anymore in many of the modern ones, such as MSVC .NET 2005.

Now, a hello world is like this:
#include <iostream>
using namespace std;
int main(void) { cout << "hello"; system("pause"); return 0; }

Although you might think that the only thing that changed was the "using namespace std" line, <iostream> and <iostream.h> are not the same files.
C++ standard library headers (Warning, only C++'s, C's remain unchanged) don't have .hs anymore. They are now <iostream> <fstream> <string> <vector> etc, and they are all wrapped now into a namespace called std.

Sp0rky

2007-04-20 19:29:07

haha at this topic title, made me rofl.

Will edit this post a bit please with code you can try.

ditto

2007-04-30 19:23:23

Wow wtf…dude do this.

#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
cout << "Hello World" << endl;

getch();
return 0;
}

getch() found in conio.h will stop it from closing.

Macrosoft

2007-08-22 15:09:58

You have to Say

Using Namespace std;

Also, you iostream include is incorrect, try

#include <iostream>

(take away the .h)

Good Luck in learning C++!

Dan Cardin

2007-08-22 15:49:51

i know u meant well, but its been almost 4 months since that last post (im not sure it would take him 4 months to make a hello world)

[BANANA]NOOBNOOBNOOBNOOBNOOBNOOBNOOBNOOBNOOBNOOBNOOBNOOB
[LEFT]You, Macrosoft, have been reported for being a NOOB.
Your
Current violations include
  1. Grave Digging for
This brings you to a new total of (2) Noob Points!

For more information on Macrosoft please go Here.

For more information from This database please go Here.

For more information on The Noob Points System please go Here.

For more information on Noobs please go Here.

[/LEFT]
NOOBNOOBNOOBNOOBNOOBNOOBNOOBNOOBNOOBNOOBNOOBNOOB[/BANANA]

edit: if u dont already know, the points will gradually go away