Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 help with beginning code
Index -> Programming, C++ -> C++ Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
deathscith




PostPosted: Fri Oct 17, 2008 7:11 pm   Post subject: help with beginning code

code:

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


should probably of stated more in the subject name, but it isnt really help needed for the hello world code, i use the compiler MinGW, and everytime i compile this program, and i've done this with devC++, the problem is that when i compile it, it creates an exe oviously, and when i open the exe it opens it in cmd promt, but it closes instantly... how do i get it to stay open?
Sponsor
Sponsor
Sponsor
sponsor
deathscith




PostPosted: Fri Oct 17, 2008 7:25 pm   Post subject: Re: help with beginning code

alright, well could anyone help me with my quick solution? make it so it awaits a command to exit?
kinda like for turing (only language i know much of)

code:

var base : string := ""
var exitstate :string
loop
put "hello world"
get exitstate
if exitstate = base then
put ""
else
exit
end loop
wtd




PostPosted: Fri Oct 17, 2008 7:28 pm   Post subject: RE:help with hello world

This is a common issue.

http://wiki.compsci.ca/index.php?title=Window_closes_instantly
[Gandalf]




PostPosted: Fri Oct 17, 2008 7:43 pm   Post subject: RE:help with beginning code

Open it in the command line, cmd.exe on Windows. Simple C/C++ programs aren't meant to be run in they way you are attempting to run them.

Also, don't post "bump" 2 minutes after you post your help topic.

*edit* No refresh, wtd wins.
deathscith




PostPosted: Fri Oct 17, 2008 8:24 pm   Post subject: Re: help with beginning code

i'll remember that gandalf, and as for my problem, the link you said gave me this as my desired outcome
Quote:

This is the poorer choice, and only masks the problem. Add code to your program that prompts the user for input. The program will not complete until the user actually does input something, meaning that in the meantime the console window remains open.


but how do i do that?
wtd




PostPosted: Fri Oct 17, 2008 8:28 pm   Post subject: RE:help with beginning code

Good question. You have something new to learn.
deathscith




PostPosted: Fri Oct 17, 2008 8:30 pm   Post subject: Re: help with beginning code

where would i go about as to learning this? i've looked through a few of the beginners tuts and they never give this info...
Tony




PostPosted: Fri Oct 17, 2008 8:37 pm   Post subject: Re: help with beginning code

I just want to point out that...
deathscith @ Fri Oct 17, 2008 8:24 pm wrote:
the link you said gave me this as my desired outcome
Quote:

This is the poorer choice...
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Sponsor
Sponsor
Sponsor
sponsor
deathscith




PostPosted: Fri Oct 17, 2008 9:27 pm   Post subject: Re: help with beginning code

Tony @ Fri Oct 17, 2008 8:37 pm wrote:
I just want to point out that...
deathscith @ Fri Oct 17, 2008 8:24 pm wrote:
the link you said gave me this as my desired outcome
Quote:

This is the poorer choice...

yea, but its what i want it to do.
Ktomislav




PostPosted: Sat Oct 18, 2008 8:24 am   Post subject: Re: help with beginning code

code:

#include <iostream.h>
using namespace std;
main(void)
{
    int a;
    cout << "Hello World!";
    cin >>a;
    return 0;
}


That's the way i do.
michaelp




PostPosted: Sat Oct 18, 2008 9:36 am   Post subject: RE:help with beginning code

Also, it should be:

code:
#include <iostream>


not

code:
#include <iostream.h>
wtd




PostPosted: Sat Oct 18, 2008 11:37 am   Post subject: RE:help with beginning code

Congrats on just feeding deathscith an easy answer.
Ktomislav




PostPosted: Sat Oct 18, 2008 4:20 pm   Post subject: Re: RE:help with beginning code

michaelp @ 18.10.2008, 15:36 wrote:
Also, it should be:

code:
#include <iostream>


not

code:
#include <iostream.h>


Yes. I copied that code from the post above and i didn't check it if it is correct.
Rigby5




PostPosted: Fri Oct 24, 2008 5:48 pm   Post subject: RE:help with beginning code

cin >> a
will wait until you hit the <ret> key.
If instead you use
int c = getch();
They any single key at all will work to end it.
md




PostPosted: Sat Oct 25, 2008 12:38 am   Post subject: RE:help with beginning code

cout and cin are not in the standard name space, problem number one.

waiting for needless input at the end of your program is such a bad practice that anyone who recommends it should be shot. Or failing that banned from programming. Ever.

Instead you should run your program from a command line, like command line programs are mean't to be run. Compilers are command like programs too! So if you compile your code using a compiler on the command line you already have a ready to use window to run your just created executable in! Plus using the command line will get you much more familiar with the compiler and many other different parts of your system which are really quite handy.


Rigby5, getch is a windows only function. Unless you include some additional libraries which are well beyond a hello world program, getch will not exist.
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 22 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: