PDA

View Full Version : Need help with my Hello World app.



Ron
03-01-2007, 04:47 PM
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
03-01-2007, 04:58 PM
try this:

program New;
begin
Writeln('Hello world');
end.

lol, thats easier then C++ if you ask me :p

omgh4x0rz
03-01-2007, 05:14 PM
Lol. Jad, he is writing in C++, not anything to do with scar!

Ron, try doing this.

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

JAD
03-01-2007, 06:20 PM
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
03-03-2007, 04:27 PM
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
03-03-2007, 05:10 PM
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
03-03-2007, 09:40 PM
:( Same problem. Thanks any way KuJi.

omgh4x0rz
03-06-2007, 08:40 PM
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
03-06-2007, 08:44 PM
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
03-06-2007, 09:58 PM
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
03-07-2007, 07:27 PM
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
03-25-2007, 09:32 AM
you are starter with c++ ?

marneus901
03-25-2007, 07:27 PM
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
04-20-2007, 11:25 PM
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
04-20-2007, 11:29 PM
haha at this topic title, made me rofl.

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

ditto
04-30-2007, 11:23 PM
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
08-22-2007, 07:09 PM
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
08-22-2007, 07:49 PM
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)

NOOBNOOBNOOBNOOBNOOBNOOBNOOBNOOBNOOBNOOBNOOBNOOB

You, Macrosoft, have been reported for being a NOOB.
Your Current violations include Grave Digging for http://www.greg.impwiki.org/noobpoints/noobpoints.png (http://www.villavu.com/forum/showthread.php?t=5265) http://www.greg.impwiki.org/noobpoints/noobpoints.png (http://www.villavu.com/forum/showthread.php?t=5265)
This brings you to a new total of http://www.greg.impwiki.org/noobpoints/noobpoints.png (http://www.villavu.com/forum/showthread.php?t=5265)http://www.greg.impwiki.org/noobpoints/noobpoints.png (http://www.villavu.com/forum/showthread.php?t=5265) (2) Noob Points!

For more information on Macrosoft (http://noobpoints.tehintar.net/noobadmin.php?noob_name=Macrosoft) please go Here. (http://noobpoints.tehintar.net/noobadmin.php?noob_name=Macrosoft)

For more information from This database (http://noobpoints.tehintar.net/noobadmin.php) please go Here. (http://noobpoints.tehintar.net/noobadmin.php?)

For more information on The Noob Points System (http://noobpoints.tehintar.net/) please go Here. (http://noobpoints.tehintar.net/)

For more information on Noobs (http://www.villavu.com/forum/showthread.php?t=5265) please go Here. (http://www.villavu.com/forum/showthread.php?t=5265)

NOOBNOOBNOOBNOOBNOOBNOOBNOOBNOOBNOOBNOOBNOOBNOOB

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