Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 12-18-2003, 11:00 PM   #1 (permalink)
Booker44
Registered User
 
Join Date: Dec 2003
Posts: 3
Booker44 is on a distinguished road
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!
Booker44 is offline   Reply With Quote
Old 12-19-2003, 10:50 AM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
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
sde is offline   Reply With Quote
Old 12-19-2003, 11:23 AM   #3 (permalink)
Booker44
Registered User
 
Join Date: Dec 2003
Posts: 3
Booker44 is on a distinguished road
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!
Booker44 is offline   Reply With Quote
Old 12-19-2003, 12:31 PM   #4 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
Valmont is on a distinguished road
:)

// my first program in C++
#include <iostream.h>
int main ()
{
cout <<"Hello World!";

cin.get();
return 0;
}
__________________
Valmont is offline   Reply With Quote
Old 12-19-2003, 09:58 PM   #5 (permalink)
Booker44
Registered User
 
Join Date: Dec 2003
Posts: 3
Booker44 is on a distinguished road
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.
Booker44 is offline   Reply With Quote
Old 12-20-2003, 08:53 AM   #6 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
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
sde is offline   Reply With Quote
Old 12-20-2003, 09:04 AM   #7 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
Valmont is on a distinguished road
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 .
__________________
Valmont is offline   Reply With Quote
Old 12-27-2003, 09:28 AM   #8 (permalink)
blue fire
Registered User
 
blue fire's Avatar
 
Join Date: Dec 2003
Location: London, England
Posts: 2
blue fire is on a distinguished road
Smile

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
blue fire is offline   Reply With Quote
Old 12-27-2003, 09:35 AM   #9 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
Valmont is on a distinguished road
__________________
Valmont is offline   Reply With Quote
Old 12-27-2003, 11:23 AM   #10 (permalink)
L06@N
Registered User
 
L06@N's Avatar
 
Join Date: Dec 2003
Location: Nebraska, USA
Posts: 17
L06@N is on a distinguished road
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.
L06@N is offline   Reply With Quote
Old 12-27-2003, 12:32 PM   #11 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
Valmont is on a distinguished road
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.
__________________
Valmont is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 04:32 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting