|
 |
|
 |
12-18-2003, 11:00 PM
|
#1 (permalink)
|
|
Registered User
Join Date: Dec 2003
Posts: 3
|
Getting started
Okay, I am VERY new to coding and have only just begun reading tutorials in C++ and putting together tiniest bits of code. The problem is I have downloaded the DevC++ (v.4) compiler and I am not seeing results. I copied the standard "Hello world" 7 lines of code, successfully compiled it, but I have no idea how to view it. Am I getting in over my head? Should I start with a different language? Please use small words so I can understand!
|
|
|
12-19-2003, 10:50 AM
|
#2 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,444
|
nah, it's all part of the learning process. the best thing when learning on your own is to use tutorials, and use places like this for help.
the best way to use the forum is to copy code bits .. if it's only 7 lines of code, then copy the whole thing, .. otherwise, copy the bit of code where you think the problem is.
along with the code, explain the results you get. something like: " i run the program, it opens and closes immediately "
c++ is a great langauge to learn, and since lots of other languages are based on c style syntax, it is easier to pick up new languages in the future.
so with that said, .. post code and let us know what happens when you execute the program! have fun

__________________
Mike
|
|
|
12-19-2003, 11:23 AM
|
#3 (permalink)
|
|
Registered User
Join Date: Dec 2003
Posts: 3
|
Okay, here's what I am doing. I copied a small piece of sample code from a tutorial for the sole purpose of getting familiar with the mechanics. That way I can copy larger pieces of code, and see results when I make changes to it. The code I copied first was-
// my first program in C++
#include <iostream.h>
int main ()
{
cout <<"Hello World!";
return 0;
}
I then pressed the "compile and run" button on the Dev-C++ tool bar. The screen flashed, then a message appeared in the compiler at the bottom of the screen stating that prog1.cpp was compiled successfully, but no other results.
I originally entered the program in crimson editor, but after realizing I needed a separate compiler I downloaded Dev-C++ and opened the file in that, I don't think that makes a difference, but I am trying to be specific here.
I apologize if these questions are incredibly simple, but I don't really know anyone to ask. So far (not that I am that far along) I am having no problem understanding the structure and logic of the code itself (which I expected... which is why I am trying this!), it is just the programs I am using to write and compile it!
|
|
|
12-19-2003, 12:31 PM
|
#4 (permalink)
|
|
[code][/code] enforcer
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
|
:)
// my first program in C++
#include <iostream.h>
int main ()
{
cout <<"Hello World!";
cin.get();
return 0;
}
__________________
|
|
|
12-19-2003, 09:58 PM
|
#5 (permalink)
|
|
Registered User
Join Date: Dec 2003
Posts: 3
|
That did it! Thank you!
The tutorial I am using is http://www.cplusplus.com/doc/tutorial/
I copied the piece of code directly from that, and considering it didn't work, it has lost alot of credibility with me. I'll keep looking around. Perhaps it is best to learn from multiple tutorials to avoid situations like that. Thank you again, you have reassured me of my sanity.
|
|
|
12-20-2003, 08:53 AM
|
#6 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,444
|
it's pretty common to get confused about that. what happened was that the program ran just fine and then closed itself.
since it goes so fast, you don't really see the 'hello world'
val added the line of code which makes the program wait for user input so it won't close before you can see it.
after you press a key, it hits 'return 0' and closes.
__________________
Mike
|
|
|
12-20-2003, 09:04 AM
|
#7 (permalink)
|
|
[code][/code] enforcer
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
|
I've looked briefly into that tutorial.
It is not up to date (regarding c++ standards) but definatly good as a free tutorial.
Note that on Visual C+ you don't add cin.get() in the debug mode, but you do add it for the release *.exe if you make a console program.
Now what you can do is to find out if DevC++ works exactly the other way around. I worked once with DevC++ but that was a long time ago. So I forgot. Anyway, experiment a lil.
My second advice is to pay attention to character/string handling very well. The student can be as smart as anyone can be, but if he doesn't handle "standart output and standard input" (chars/strings mostly thus) really well, he will always struggle.
And obviously you can always show your face here if you like some help  .
__________________
|
|
|
12-27-2003, 09:28 AM
|
#8 (permalink)
|
|
Registered User
Join Date: Dec 2003
Location: London, England
Posts: 2
|
Hi
I'd like to say thanks to valmont for that piece of coding.
The same thing kept happening whenever I compiled something, and
so I kept looking for other compilers, thinking that it must have
been the compiler's fault, as every other website with the hello world code would not work.
Many thanks
|
|
|
12-27-2003, 09:35 AM
|
#9 (permalink)
|
|
[code][/code] enforcer
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
|
__________________
|
|
|
12-27-2003, 11:23 AM
|
#10 (permalink)
|
|
Registered User
Join Date: Dec 2003
Location: Nebraska, USA
Posts: 17
|
The other way to run it w/o the cin.get(); is to compile it to .exe format and then run the .exe file from the Shell (aka DOS) prompt, but that does take a bit longer to do and is more or less the long way around it.
|
|
|
12-27-2003, 12:32 PM
|
#11 (permalink)
|
|
[code][/code] enforcer
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
|
Quote:
Originally posted by L06@N
The other way to run it w/o the cin.get(); is to compile it to .exe format and then run the .exe file from the Shell (aka DOS) prompt, but that does take a bit longer to do and is more or less the long way around it.
|
Basically that is the one and only correct way since it is a CONSOLE program after all. So good point there.
But if you don't wan't to start up the console (command) then use
"cin.get()" in a loop wich checks for a key-press and exits. This way you can can just double-click on your console proggy and use it like it is.
__________________
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -8. The time now is 04:32 PM.
|
Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
|
 |
|