hello world error?

Hi, I'm a noob.I paste this code:
1
2
3
4
5
6
7
8
#include <iostream>
using namespace std;

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

to see what will happens, but nothings happens. I paste it in new window application, and compile it then run, but it still nothing happens. Is there any problems?
There is nothing wrong with it per say. You just need another line to make it where the program waits till you press enter to exit the program. That way you get to see the program run.

the line is:

system("PAUSE")

Here is the code with that included (Line 7):

1
2
3
4
5
6
7
8
9
#include <iostream>
using namespace std;

int main ()
{
  cout << "Hello World!";
system("PAUSE");
  return 0;
}
Last edited on
Yea, thanks, but it become a Ms-DOS type program
Yes. I am not much farther along than you. I hope the cool stuff comes along soon. But you have to learn to crawl before you run.
Hello guys :D
I see that this problem is posted a lot by people here. This means you guys don't read posts before you post.

http://www.cplusplus.com/forum/beginner/1988/

This is a topic about your problem. Hope it helped :D

P.S: It is a sticky topic in the beginners forum, so instead of making a new topic, you could have read it. It's the first topic you see here :D
Last edited on
But my problems is when i put the system("PAUSE"); the exe. become ms-dos type although i use the window application mode compiler.
Last edited on
You have to build your GUI
Nnnngggg....

Every time I see a console referred to as MS-DOS my stomach tries to digest itself.
Unless you're using a very old compiler (which you shouldn't anyway), nowadays its impossible to generate code for DOS.
DOS was a 16-bit operating system that used a console as its main user interface (that's not to say it was the only one).
A console is a text-based user interface that takes input from the keyboard and places text-only output on a screen (although it's possible to make a console that sends its output to a printer for logging purposes).

The console seen today in Windows is 32-bit however you look at it. A program that uses it may be as much of a Windows program as notepad.exe, the only difference between the two being that one has a GUI and the other doesn't.
cmd.exe, as the current Windows console is called, is capable of running DOS programs by emulating it.
Ehe, How to build gui? I start over it with press the new buttons, then in the gui tab, there are two things (fox1.4.9 and another is fox). I choose the first second(fox) then then paste the code in at the very under of the code, after that I compile it and it come out 2 error message like (`int main()' ) conflicts with)(below first code) and another error message is (`int main(int, char**)' here )(below the second code) and fail to build it.

1
2
3
4
5
6
7
8
#include <iostream>
using namespace std;

int main ()
{//the error message said the bracket has
  cout << "Hello World!";
  return 0;
}


1
2
3
4
5
6
7
8
9
10
11
12
13
int main(int argc, char **argv)//i only copy the part of the gui or fox that the error message appear 
{//the error said this brackets has error
        FXApp app("FOX Application", "Foobar Corporation");
        app.init(argc, argv);

        MainWindow *w = new MainWindow(&app);
        app.addSignal(SIGINT, w, MainWindow::ID_QUIT);
        app.create();
        w->show(PLACEMENT_CURSOR);
        w->setFocus();

        return app.run();
}
Are both the mains in the same source file? You cannot have multiple main functions defined.
You mean I have to make new file in the project tab? before this i'm really only paste both of them in once in a same place. Now i make new project after make the GUI, and paste the hello world code again, then compile it and run, but one error message come out again" [resources error] no resources". Then i compile it again more error message came out" multiple definition of `main' " and " first defined here " and " cannot find -lpng " and " ld returned 1 exit status ".
Last edited on
You can't have two functions named main, and both of those functions are called that.

Either you're going to have to remove one function completely, or rename one and call it with the other.
"I found a tutorial, but meet a problems. before that, I want to make sure does resource.h exists or not?
resource.h is not a standard include file, its something the user would create themselves.
Oh, i see, i admit that i a bit weak in English, i don't very understand how to link two or more code together that this tutorial(http://www.winprog.org/tutorial/resources.html) teach.
That link gives me a 404.
Oh sorry, i didn't notice it. Paste this http://www.winprog.org/tutorial/resources.html on the navigate bar
On the home page of that tutorial site you can download the source code for all of the examples there. Find the source from that example and you can learn from it.
Topic archived. No new replies allowed.