My first C++ program failed on me revisted

W

Web Developer

complete code:

#include <iostream>

int main()
{
std::cout << "Hello World" << '\n';
return 0;
}


I'm using Dev C++ version 5.0 to compile the program. I don't get any errors
when compiling, but when I execute the program a DOS windows opens and then
closes straight after. I assume that this means there is nothing outputted
on screen. Any help appreciated.


WD
 
A

Artie Gold

Web said:
complete code:

#include <iostream>

int main()
{
std::cout << "Hello World" << '\n';
return 0;
}


I'm using Dev C++ version 5.0 to compile the program. I don't get any errors
when compiling, but when I execute the program a DOS windows opens and then
closes straight after. I assume that this means there is nothing outputted
on screen. Any help appreciated.
Your code is fine. It's just that after writing the message to cout
there was
nothing for the program to do -- so it went away.

You could out a call to std::getchar() before the `return' statement to
keep it around.

BTW - this is not a C++ question; it's related to your IDE.

HTH,
--ag
 
N

Noah Roberts

You could out a call to std::getchar() before the `return' statement to
keep it around.

Or learn how the command line works as any worthwhile developer should.
It is not hard to learn and is absolutely necissary for anyone serious
about learning to program for or administer systems. Not learning to
use the command line is like turning bolts with a pair of pliers - it
might work much of the time but you would certainly be better off
learning to use a wrench.

NR
 
A

Artie Gold

Noah said:
Or learn how the command line works as any worthwhile developer should.
It is not hard to learn and is absolutely necissary for anyone serious
about learning to program for or administer systems. Not learning to
use the command line is like turning bolts with a pair of pliers - it
might work much of the time but you would certainly be better off
learning to use a wrench.

NR

No argument there! ;-)

--ag
 
W

Web Developer

Or learn how the command line works as any worthwhile developer should.
It is not hard to learn and is absolutely necissary for anyone serious
about learning to program for or administer systems. Not learning to
use the command line is like turning bolts with a pair of pliers - it
might work much of the time but you would certainly be better off
learning to use a wrench.

NR

how does using a cmmand line fix my problem?

WD
 
W

Web Developer

how does using a cmmand line fix my problem?

WD

Nevermind that comment. Although, it is a nusiance to go to DOS and run the
program everytime you change some code. Maybe the Dev C++ has something like
command line?


WD
 
N

Nils Petter Vaskinn

Nevermind that comment. Although, it is a nusiance to go to DOS and run
the program everytime you change some code. Maybe the Dev C++ has
something like command line?

Make a function void pause() that prints something like "Program done
press any key to exit" and reads a character before it returns. Put that
at the end of your main.

Make a second function void my_exit(int ec) that calls pause and then
exit(ec), use that wherever you would use exit.

Remove the functions and the calls to them if you're releasing your
programs.

hth
NPV
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top