# uhh......can't write hello world?!?!?!



## semidevil (Jun 23, 2002)

to you guys, this should be easy, but to a newbie, this is like rocket science.


So I just brought a book today. called Teach yourself C++. It came w/ the Dev C++ compiler, which I installed. I did exactly what the book told me to do I put in the HelloWorld code, and compiled it. It ran completely fine. But when I exectuted it, I didn't get an output. All that happened was my compiler minizmized really really quick, and popped back up. no output, no nothing.

But.........for simplicity sake, I saved my projects on my desktop, so after trying to execute it, 3 or 4 new files appeared on my desktop. That's all I got........

hmm....so if I can't even run the very first program, it's kind of pointless to go on further into the book no?

help


----------



## Davey7549 (Feb 28, 2001)

Semidevil
I do not know C++ so I cannot help with actual code but I do know your desktop is a unique animal and can cause many unusual problems when is code sitting on it and being executed from it. You may try creating a folder and moving all the code into the folder then try executing it from there. You may also consider moving the folder to your Documents.
Just a thought!
Dave


----------



## semidevil (Jun 23, 2002)

hi Dave,

yea, it turns out that it didn't work. I created a folder inside my C drive called "codes" and saved my projects in there.

Again, the program compiled fine, but when it came time to actually run it, all my compiler did was minimize really really quick and maximize back on screen.

again, 6 files appeared on my codes folder

Project.dev
Project~2.exe
Project1.cpp
Project1.o
rsrc.o
Rsrc.rc

dont know........

heck, here is the code that I put.
===========================================

#include <iostream>

int main()
{
std::cout << "hi\n";
return 0;

}
=================================


----------



## eddie5659 (Mar 19, 2001)

Hiya

I have used Borland to learn how to compile, so this is the basics for the hello World:

You say you use this:

==============================================

#include

int main() 
{ 
std::cout << "hi\n"; 
return 0;

}

==============================================

Now, is that it? What you don't have in there is a getch. For example, try this. Also, not sure if you have the standard #includes in, but I'll put a simple program in:

==============================================

#include condefs.h
#include stdio.h
#include stdlib.h
#include iostream.h
#include conio.h
#pragma hdrstop

int main(int argc, char **argv)
{
cout << "hello World!" << endl;

cout << endl << "Press any key to continue...";
getch();
return 0;
}

==============================================

*edit* Okay. The words condefs.h, stdio.h, stdlib.h, iostream.h, conio.h and hdrstop need to have the <'s and >'s surrounding them.

There are 2 spaces in front of the cout to return. In other words, as I can't get the spaces to post, just put the {'s in, and the beginning of each line in between, add 2 spaces. if you get my drift

As I say, the #includes may already be set up, but the getch produces a keystroke type of effect. Also, you don't have any endl's in there.

Regards

eddie


----------



## semidevil (Jun 23, 2002)

hmm, do you tink it's the compiler? Is there a different I should/could try?

Eddie, 

I copied your code onto my compiler, and it got the same result....


----------



## eddie5659 (Mar 19, 2001)

Whats the complier you're using?

In the book, what does it suggest for the Hello world program? Was that all it gave, when you posted the code.


Did you put those spaces in, that I tried to mention?

eddie


----------



## eddie5659 (Mar 19, 2001)

Hang on, there's bits missing in mine 

I'll edit it, so look back at it in a minute

Okay, all done 

eddie


----------



## semidevil (Jun 23, 2002)

hm........that's wierd......still the same problem. I dno't know.........I"m getting frustrated now


----------



## DJ [email protected] (Aug 8, 2001)

what OS are you using? i have the same problem in WinXP and im not sure if this would happen in other OSes. try copying the EXE file (Project~2.exe) to C:\ and click Start>Programs>Accessories>Command prompt or MS-DOS Prompt and type 

C:\Project~2.exe

and it should work fine 

good luck


----------



## IMM (Feb 1, 2002)

*Eddie* - is this what you're chasing? 
----------
#include <condefs.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>
#pragma hdrstop

int main(int argc, char **argv)
{
cout << "hello World!" << endl;

cout << endl << "Press any key to continue...";
getch();
return 0;
}
-------------
or more simply

```
#include &lt;condefs.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;iostream.h&gt;
#pragma hdrstop

int main(int argc, char **argv)
{
  cout << "hello World!" << endl;

  cout << endl << "Press any key to continue...";
  getch();
  return 0;
}
```
You can view the source on this page to see how I did it.
As a side note - those spaces shouldn't matter to the compiler at all - they are merely readability issues and unless he's using precompiled headers and you feed the hdrstop a filename - I'd leave it out.


----------



## DJ [email protected] (Aug 8, 2001)

hmmm.. ur making a simple task WAY more complicated. as i am new to C++ as well i understand what hes going through and you guys cant be helping


----------



## eddie5659 (Mar 19, 2001)

Sorry, DJ [email protected], just lost myself in the moment. First reply in Developement....ever 

semidevil:

I have Win2000, and the code that I put worked well. Whats the company that made the compiler?

The Project1.cpp looks like its the code, or at least the name of the program that you are trying to run.

hang on, just realised I have something missing in my code. I'll edit it again, so try it once more. left out conio.


eddie


----------



## semidevil (Jun 23, 2002)

hmm.......I don't know. the compiler came w/ my book, and it is called Dev C++. I think you can d/load it too. 

but yea, I dont' know. I still can't get hello world. The code HAS to be right because I just copied right out of the book.

btw, when you install a compiler on your pc, is that all you need to do? aer there special settings that I need to configure before getting it to work properly?

I dont' know, could there be a problem somewhere there?


----------



## eddie5659 (Mar 19, 2001)

Hiya

When I installed mine from Borland, that was all I had to do.

The bit of code that you have given right at the beginning: was that all that it said in the book?

Also, were the #include's already shown in the compiler?

eddie


----------



## semidevil (Jun 23, 2002)

hmmm.......yea, that code was it. just those tiny 5 or 6 lines. As of matter of fact, the stuff that YOU typed got my head spinning!  haha, j/k.

as for the #include <iostream>, no, I had to type that in myself....the project started out as a blank application.

as for any configurations, the reason I asked is that in my java class, I had to configure like my path in autoexec.bat and stuff like to get it to run. So I was wondering if C had anything like that all....


----------



## IMM (Feb 1, 2002)

I should have written this earlier (rather than talked about how to format posts for this board  )

It looks your code linked as well as compiled to produce the executable file Project~2.exe.

This was suggested earlier - have you opened a DOS window and changed to the directory in which your code resides (c:\windows\desktop\code I think you said) and then typed Project~2.exe at the command line ??
(It's nice to have a context menu utility like DosHere for this sort of thing)

What is likely happening is that your code runs but the dos window it runs in is closing automatically after it runs (and code like that won't take very long to run  )

The code additions which were suggested merely hold the DOS window open until you hit a key.

I'm not familiar with your compiler and IDE but it lives at http://www.bloodshed.net/devcpp.html

If there is an option when you create a new project - what you need for something like this will likely be called a console type project which will create DOS like executables. There is also likely a way to run the output from within the IDE (Go or Debug or similar)


----------



## semidevil (Jun 23, 2002)

hmm..........a creating the new project as a console application did help. I saw an MS-Dos box, but it went away in a split second.......now how can I make it stay........


----------



## IMM (Feb 1, 2002)

As I said before - you can
1) run it from an already open DOS box
OR
2) add the code which will hold it open until you tap a key.
It was discussed in http://forums.techguy.org/t84500/s1cfd33b6bae538a38a721c40106de848.html
OR
3) look around in the IDE for a setting which will do it for you. It may hold open automatically if you run it in the debugger for example.


----------



## DJ [email protected] (Aug 8, 2001)

hey eddie,
i've heard you guys talking about a free borland compiler. i have been having trouble with VC++ and i would be interested in trying this. where could i download it from?

thanks


----------



## eddie5659 (Mar 19, 2001)

Er, it wasn't free. It was supplied with the book:

This is the nearest I could find:

http://www.amazon.com/exec/obidos/A...66708/sr=1-10/ref=sr_1_10/102-1241028-1173732

Though this is the main site of Borland:

http://www.borland.com/products/index.html

The one I have is an old version, and its in 14 days, though as programming is not a good point with me, I make it into 14 weeks 

Still, have to study it again. Never got past chapter 2 

eddie


----------



## DJ [email protected] (Aug 8, 2001)

sorry about that, i've seen someone talk about a free version of borland C++ compiler but never mind, i can stick with VC++


----------



## Snake~eyes (Apr 18, 2002)

> _Originally posted by DJ [email protected]:_
> *sorry about that, i've seen someone talk about a free version of borland C++ compiler but never mind, i can stick with VC++  *


yah there is such a thing.


----------



## DJ [email protected] (Aug 8, 2001)

any ideas of where to get it would be appreciated


----------



## Snake~eyes (Apr 18, 2002)

yah

click here


----------



## IMM (Feb 1, 2002)

http://forums.techguy.org/t84703/s6890af1cb4a75f919a1ef9d7b483db32.html


----------



## Snake~eyes (Apr 18, 2002)

i remember that thread and looked for it.. oh well


----------



## DJ [email protected] (Aug 8, 2001)

lol.. not helping snakey!!


----------



## Snake~eyes (Apr 18, 2002)

oh well.. lol

just chitchatting


----------



## DJ [email protected] (Aug 8, 2001)

u wanna "chit chat" head over to my site and make the forums look busy


----------



## Snake~eyes (Apr 18, 2002)

phpbb sux0rz
and i have my own sites to chitchat


----------



## DJ [email protected] (Aug 8, 2001)

lol.. wat can i say?? its free  

i downloaded a copy of vBulletin (cant say where ) but i cant get it to work as its not exactly legit and there is no instructions on how to install it


----------



## Snake~eyes (Apr 18, 2002)

Well to be honest the installation is very very easy.

But I am not going to help you with a pirated version of vbulletin.

Sorry but thats not my style.

-Snake


----------



## DJ [email protected] (Aug 8, 2001)

lol .. no problem, i wouldnt ask you to


----------



## DJ [email protected] (Aug 8, 2001)

hey, you no longer have an ethical problem as i HATE vBulletin  it has WAY too many options and settings and its too hard to find decent themes and hacks for it (for free) 

back to phpBB for me


----------



## DJ [email protected] (Aug 8, 2001)

lol.. and no-ones helping the guy who originally started this thread


----------



## Snake~eyes (Apr 18, 2002)

> _Originally posted by DJ [email protected]:_
> *hey, you no longer have an ethical problem as i HATE vBulletin  it has WAY too many options and settings and its too hard to find decent themes and hacks for it (for free) *


That is all wrong wrong wrong.

It doesnt have that many options and the hack support for it is awesome! But you'd have to be a legal vbulletin owner to know that. Also there are a bunch of free themes. And its so easy you can make your own themes easily anyways.

-Snake


----------



## DJ [email protected] (Aug 8, 2001)

lol.. i cant get into the members area 

oh well, i'll just stick with phpBB which is easy and not "pirated"


----------



## Snake~eyes (Apr 18, 2002)

the reason you cant get into the members area is because you didnt purchase it.. lol


----------



## eddie5659 (Mar 19, 2001)

semidevil:

You said that you managed to get the DOS window to open.

Now, in your code, try adding the 

getch(); 

Just before the 

return 0; 

See if that helps

eddie


----------

