Newbie Question
Author |
Message |
Pinto2
![](http://www.swob.dna.fi/ srp/hacker.gif)
|
Posted: Mon Oct 17, 2005 4:09 pm Post subject: Newbie Question |
|
|
Well, I'm new to C++ and when ever i make any programs it displays them in a MS-DOS screen, and then the screen goes away almost immediantly after. Is it supposed to appear in a MS-DOS screen, and if so how can i stop the screen from disapearing because i'm having trouble advancing in the language without seeing i'm doing. Also, after i have compiled a program (says 'hello world'), how do i change what the program does, because even after i change what the program is supposed to do (ex:count) and re-compile it, it still says 'hello world'.
Also is there a notable difference between a project or a source file. Sorry for the stupid qeustions but i just need a little help getting started and then i'll be on my way. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Pinto2
![](http://www.swob.dna.fi/ srp/hacker.gif)
|
Posted: Mon Oct 17, 2005 6:02 pm Post subject: (No subject) |
|
|
Ok, i just read some other post about C++, and i'm starting to think that Dev-C++ is not the only or best compiler. How many options for compilers do i have, and could somone suggest one that is extermly uncomplicated to get, set up, and to use seeing that i'm having a hard enough time learning the language and don't need anymore difficulties. Also, feel free to answer my questions in the post before that, thanks. |
|
|
|
|
![](images/spacer.gif) |
Monstrosity_
|
Posted: Mon Oct 17, 2005 7:19 pm Post subject: Re: Newbie Question |
|
|
Pinto2 wrote: Well, I'm new to C++ and when ever i make any programs it displays them in a MS-DOS screen, and then the screen goes away almost immediantly after.
This is by design.
Pinto2 wrote: Is it supposed to appear in a MS-DOS screen, and if so how can i stop the screen from disapearing because i'm having trouble advancing in the language without seeing i'm doing.
Open it in a command prompt instead of having windows do it for you.
Pinto2 wrote: How many options for compilers do i have, and could somone suggest one that is extermly uncomplicated to get, set up, and to use seeing that i'm having a hard enough time learning the language and don't need anymore difficulties.
It seems to me that your compiler works fine, it does its job.. to compile the code. But since everyone likes a good look around.. go look on google. Or wait a bit longer and im sure someone will come praise there favorite compiler. |
|
|
|
|
![](images/spacer.gif) |
wtd
|
Posted: Mon Oct 17, 2005 7:38 pm Post subject: (No subject) |
|
|
If you just double-click the created executable, the command prompt window will open, the program will run, and since the command-prompt window doesn't hang around any longer than necessary, as soon as your program finishes, the window closes.
Open the command prompt, "cd" to the directory where your executable is located, then run it.
The easiest way to get a simple, working C++ dev environment is to install a decent OS. Barring that, install the MinGW port of GCC. |
|
|
|
|
![](images/spacer.gif) |
Pinto2
![](http://www.swob.dna.fi/ srp/hacker.gif)
|
Posted: Mon Oct 17, 2005 10:05 pm Post subject: (No subject) |
|
|
Ok, so i would open MS-Dos, cd it to C:\WINDOWS\Desktop\Dev-Cpp and then run the program to make it stay on the screen longer? Mean while, i'm still confused why
#include<iostream.h>
#include<stdlib.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<math.h>
void main()
{ int gmode=VGA,gdriver=VGAMED;
initgraph(&gmode,&gdriver,"c:\\tc\\bgi");
do
{
for(int i=1;i<=15;i++)
{ setcolor(i);
line(random(640),random(320),320,165); //320,165
//arc(320,200,0,random(360),random(100));
delay(10);
}
clrscr();
//clearviewport(); // clear display screen in graphics mode
}while(!kbhit());
closegraph();
}
gets me 'hello world', eventhough i've re-saved it and re-compiled it.
Once again sorry for the newb questions but i just need a little 'push' in the right direction to get started. |
|
|
|
|
![](images/spacer.gif) |
wtd
|
Posted: Mon Oct 17, 2005 10:25 pm Post subject: (No subject) |
|
|
You're trying to get in way over your head. You're also writing platform-dependent code. You're using an IDE that's gdoing nothing other than confusing you.
Seriously. Go back to square one and approach problems one at a time. |
|
|
|
|
![](images/spacer.gif) |
[Gandalf]
![](http://compsci.ca/v3/uploads/user_avatars/189297994e4c716fec7f1.png)
|
Posted: Tue Oct 18, 2005 1:22 am Post subject: (No subject) |
|
|
The reason why your code still shows up as "hello world" is that that is the last successful compile you have done. You can make all the changes in the world, try to compile, fail, run it, and you will still see the same program.
Your program is not compiling, most probably because you are missing one of the libraries you are including. |
|
|
|
|
![](images/spacer.gif) |
wtd
|
Posted: Tue Oct 18, 2005 1:25 pm Post subject: (No subject) |
|
|
c++: | #include<iostream.h>
|
"iostream.h" has been deprecated. It's old, and there's no guarantee that it will work with new compilers. Beside that, you dn't actually use anything from iostream in your program.
Also, good C++ convention is to include a space between "#include" and the <.
c++: | #include<conio.h>
#include<graphics.h>
#include<dos.h>
|
There are C++ compilers for huge numbers of hardware and software platforms. You've just limited yourself to Windows.
This is the C header file for math functions. C++ uses this header, but to account for differences in the languages, the "cmath" wrapper should be used.
The "main" function should return "int".
c++: | int gmode=VGA,gdriver=VGAMED; |
You should be using whitespace around the assignment operator and the comma. Additionally, these values don't need to change, so they should be declared "const".
c++: | initgraph(&gmode,&gdriver,"c:\\tc\\bgi"); |
Whitespace is a great thing. There are many other instances of this.
"i" is a meaningless variable name. Use something more meaningful.
c++: | line(random(640),random(320),320,165); //320,165
|
What is that comment trying to tell me? In fact, it tells me nothing about the code. Useless comments are bad. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
[Gandalf]
![](http://compsci.ca/v3/uploads/user_avatars/189297994e4c716fec7f1.png)
|
Posted: Tue Oct 18, 2005 2:47 pm Post subject: (No subject) |
|
|
wtd wrote: c++: | line(random(640),random(320),320,165); //320,165
|
What is that comment trying to tell me? In fact, it tells me nothing about the code. Useless comments are bad.
Sometimes I find that I make comments like this when I am experimenting with values and don't want to forget what I previously decided on. Still, it should probably have been removed at the time of posting/the time it was no longer needed. |
|
|
|
|
![](images/spacer.gif) |
wtd
|
Posted: Tue Oct 18, 2005 2:51 pm Post subject: (No subject) |
|
|
[Gandalf] wrote: wtd wrote: c++: | line(random(640),random(320),320,165); //320,165
|
What is that comment trying to tell me? In fact, it tells me nothing about the code. Useless comments are bad.
Sometimes I find that I make comments like this when I am experimenting with values and don't want to forget what I previously decided on. Still, it should probably have been removed at the time of posting/the time it was no longer needed.
It should have been noted that keeping those values around was the reason for the comment.
c++: | // Previous values used: 320, 165
line(random(640), random(320), 320, 165); |
|
|
|
|
|
![](images/spacer.gif) |
Pinto2
![](http://www.swob.dna.fi/ srp/hacker.gif)
|
Posted: Tue Oct 18, 2005 4:31 pm Post subject: (No subject) |
|
|
Ok, thanks for the help. I understand now. Also, this is not my program that i wrote(copy/past off a tutorial), because i've only been doing this now for less than two days i don't have the skill to do it on my own yet. I'll be sure to post my first program that i make my self later on to get your opinons on that.
Thanks |
|
|
|
|
![](images/spacer.gif) |
|
|