|
From: Jeff C. <ja...@sp...> - 2001-11-29 15:43:09
|
Hello,
I'm new to C++ development; in fact I'm trying to learn by "Sams Teach
Yourself C++".
I have installed Dev-C++, and have written a test program, the program
compiles, but when running it, it only flashes quickly on the screen.
My system is a Pentium III with Windows 2000 installed, the program is
stated below, as it is in the book:
#include <iostream.h>
int main()
{
int x = 5;
int y = 7;
cout << "\n";
cout << x + y << " " << x * y;
cout << "\n";
return 0;
}
????? What am I doing wrong that the program when executed does not stay up
on the screen????
Sincerely,
Jeff
|
|
From: Jason H. <jas...@bt...> - 2001-11-29 22:57:22
|
If you add #include <cstdlib> at the top and the line: system("PAUSE"); just
before the return 0; then before the program finishes a message saying Press
Any Key To Continue will pop up and wait for you.
i.e.
#include <cstdlib>
#include <iostream>
int main()
{
cout << "Hello World!" << endl;
system("PAUSE");
return 0;
}
Jason.
----- Original Message -----
From: "Jeff Clark" <ja...@sp...>
To: "Dev-C++ mailing list" <dev...@li...>
Sent: Thursday, November 29, 2001 3:42 PM
Subject: [Dev-C++] Run Problem
> Hello,
>
> I'm new to C++ development; in fact I'm trying to learn by "Sams Teach
> Yourself C++".
>
> I have installed Dev-C++, and have written a test program, the program
> compiles, but when running it, it only flashes quickly on the screen.
>
> My system is a Pentium III with Windows 2000 installed, the program is
> stated below, as it is in the book:
>
>
>
> #include <iostream.h>
>
> int main()
> {
> int x = 5;
> int y = 7;
> cout << "\n";
> cout << x + y << " " << x * y;
> cout << "\n";
> return 0;
> }
>
> ????? What am I doing wrong that the program when executed does not stay
up
> on the screen????
>
>
> Sincerely,
>
> Jeff
>
>
>
>
>
>
>
>
>
>
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|
|
From: Charles <cha...@at...> - 2001-11-29 23:32:57
|
Jeff -
> > I have installed Dev-C++, and have written a test program, the program
compiles, but when running it, it only flashes quickly on the screen.
Note that Jason's solution,
> If you add #include <cstdlib> at the top and the line: system("PAUSE")
is system-specific and therefore not portable.
It is better to do this:
#include <cstdio>
printf("Press ENTER to continue");
fflush(stdout);
getchar();
Chuck
|
|
From: christiaan s. <ck...@ia...> - 2001-12-01 13:22:46
|
whats wrong with pause?
----- Original Message -----
From: "Charles" <cha...@at...>
To: "Dev-C++" <dev...@li...>
Sent: Friday, November 30, 2001 1:27 AM
Subject: Re: [Dev-C++] Run Problem
> Jeff -
>
> > > I have installed Dev-C++, and have written a test program, the program
> compiles, but when running it, it only flashes quickly on the screen.
>
> Note that Jason's solution,
> > If you add #include <cstdlib> at the top and the line: system("PAUSE")
> is system-specific and therefore not portable.
>
> It is better to do this:
>
> #include <cstdio>
>
> printf("Press ENTER to continue");
> fflush(stdout);
> getchar();
>
>
> Chuck
>
>
>
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|
|
From: Charles <cha...@at...> - 2001-12-01 19:11:18
|
Christiaan -
> whats wrong with pause?
>
> > Note that Jason's solution,
> > > If you add #include <cstdlib> at the top and the line: system("PAUSE")
> > is system-specific and therefore not portable.
> >
> > It is better to do this:
> >
> > #include <cstdio>
> >
> > printf("Press ENTER to continue");
> > fflush(stdout);
> > getchar();
When I say that it is not portable I mean that "pause" will not work on all
systems. I found this out recently because I have used it too. I made some
changes to my computer (installed Windows 98SE, switched to the Cygwin
compiler etc.). Now system("pause") will not work for me.
Code portability is a good thing.
Chuck
|
|
From: Jason H. <jas...@bt...> - 2001-12-01 22:51:35
|
I only used it because it because it's quick, simple and gets the job done
with only one line of code. In other words I'm lazy. I agree it's not
portable, although it should work with your average Dev-C++ installation. In
most cases portability isn't an issue as I think most people use it only for
test programs.
Jason.
----- Original Message -----
From: "Charles" <cha...@at...>
To: "christiaan scholtz" <ck...@ia...>;
<dev...@li...>
Sent: Saturday, December 01, 2001 7:03 PM
Subject: Re: [Dev-C++] Run Problem
> Christiaan -
>
> > whats wrong with pause?
> >
> > > Note that Jason's solution,
> > > > If you add #include <cstdlib> at the top and the line:
system("PAUSE")
> > > is system-specific and therefore not portable.
> > >
> > > It is better to do this:
> > >
> > > #include <cstdio>
> > >
> > > printf("Press ENTER to continue");
> > > fflush(stdout);
> > > getchar();
>
> When I say that it is not portable I mean that "pause" will not work on
all
> systems. I found this out recently because I have used it too. I made
some
> changes to my computer (installed Windows 98SE, switched to the Cygwin
> compiler etc.). Now system("pause") will not work for me.
>
> Code portability is a good thing.
>
> Chuck
>
>
>
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|
|
From: <ad...@Ho...> - 2001-12-03 07:46:44
|
Hi!
I'm new with the C language programming.
I'am having some trouble with the portable solution Charles sent in
previous message. It workeb fine until I included one more printf() line
before it, like the following example. I had to replace it with the
system(pause) line.
...
printf("x value is: %d\n",som);
printf("Press ENTER to continue...");
fflush(stdout);
getchar();
Note that I use stdio.h instead of cstdio, is it because of that?
--
Andr=E9 Duc-Taffe ad...@ho...
:::::::::::::::::::::::::::::::::::::::::::::::::
http://www.lescastro.fr.st
http://www.exempligratia.net
|
|
From: Charles <cha...@at...> - 2001-12-03 21:34:24
|
André -
> I'am having some trouble with the portable solution Charles sent in
previous message. It workeb fine until I included one more printf() line
before it, like the following example. I had to replace it with the
system(pause) line.
...
printf("x value is: %d\n",som);
printf("Press ENTER to continue...");
fflush(stdout);
getchar();
> Note that I use stdio.h instead of cstdio, is it because of that?
Probably not.
Comment out the first printf. Does the program work now? If it does, look
in the first printf statement for a problem. What errors are the compiler
or the linker giving you? Did you define som?
I tried this program:
#include <cstdio>
int main(int argc, char *argv[]){
int som=100;
printf("x value is: %d\n",som);
printf("Press ENTER to continue...");
fflush(stdout);
getchar();
return 0;
}
and received this output:
x value is: 100
Press ENTER to continue...
By the way, #include <stdio.h> also works.
Chuck
|