Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 16th, 2005, 11:06 AM   #11
Broax
Hobbyist Programmer
 
Broax's Avatar
 
Join Date: Jan 2005
Location: Porto, Portugal
Posts: 142
Rep Power: 4 Broax is on a distinguished road
Send a message via MSN to Broax
I think I'm having good teachers.. :p

Anyway, now that I somehow understand the basic concept behind OOP which free sites, tutorials, manuals, etc. do you recomend to me? I've been browsing around and found some but since I'm learning the first language I don't know if these are any good for me.

Also I found a site that said that I can get involved in some project on sourceforge and learn by doing there. But I think that would be getting me ahead of myself, 'cause first I should learn the baiscs...

D'ya have any suggestions?
Broax is offline   Reply With Quote
Old Jan 16th, 2005, 5:41 PM   #12
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
The basic idea is not to concentrate on each line of code, but what it's doing and how it's doing it instead. In the long run this will be MUCH more beneficial to your programming skillz.
__________________

tempest is offline   Reply With Quote
Old Jan 16th, 2005, 8:06 PM   #13
Broax
Hobbyist Programmer
 
Broax's Avatar
 
Join Date: Jan 2005
Location: Porto, Portugal
Posts: 142
Rep Power: 4 Broax is on a distinguished road
Send a message via MSN to Broax
Ok... So I've went to the tutorials forum and I've read this one which I found a bit confusing. So after reading some more someone suggested this site which I decided to take a look at. (I would really like if some one could give me an opinion about it)

Anyway. After the first lesson I've memorized enough stuff to do the very simple code that follows, but I'dd really like someone to take a look at the comments I made to see if I got it all straight.

Feel free to correct me even at the more simple erros like "call that X instead of Y, 'cause it's more acurate..." and stuff like that. Anyway, really simple code follows:

/* This is my first attempt at 
some real programming! I'm using
the tutorial available from 
http://www.cplusplus.com/ and this 
what I've memorized from my first 
lesson. (this of course, being
the comment block) */

//And this would be the comment line!
#include <iostream.h> //The # serves to pre-load stuff like, in this case the iostream "library"

int main() //int starts a function, in this case "main" which is the backbone of the program.
{//this starts to specify the code of a given function
    cout << "testeeeee"; //cout serves to output something (in this case text) although I think it would porbably output other stuff like variables and the sorts...
    
    return 0; //this signals the end of a function
}//and this marks the end of the code of the same function.

I also take this chance to thank the help so far and appologize if something that I ask could be answered in google by some page I missed.

Also please forgive any poor english but I'm Portuguease so I recon some errors come while speaking another language...

EDIT: Some simple questions, BTW... why is there a "<<" in cout? and what exactly happens when the computer reads the "return 0" line? Also what does the iostream.h library do?
Broax is offline   Reply With Quote
Old Jan 16th, 2005, 9:42 PM   #14
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 8 Ooble is on a distinguished road
The << is a weird thingy that you don't need to know about. I barely understand it myself. All you need to know is that to print more than one thing, you just add it on the end:
cout << "Blah " << "More Blah" << endl;
endl stands for "end-line" and is used to create a line break.

iostream.h is a library containing several input and output functions, so you don't need to write them yourself. cout is one of these - it's not part of the language, but part of iostream.h, or Input/Output Stream Header. Actually, if you want to use ANSI C++, which is the more up-to-date version, you should use #include <iostream> (without the .h). You then use std::cout instead of cout, as it is part of the Standard Library in this header file. Of course, most people find this annoying, so you can also add
using namespace std;
after the #include. This instructs the compiler to use std whenever it can. You can then just use cout.

And finally, return 0. If you look above, you'll see it says int main(). The int part specifies this function returns an integer. As it is the main function, it returns it to the operating system, which can then parse the number and do something depending on it. But unless you're writing an application that interfaces with another in some way, I suggest leaving it as return 0. You can also use this statement before the end of the function to exit the program early.

If any of this is incomprehensible, I apologise - it's nearly 4am.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Jan 17th, 2005, 5:19 AM   #15
Broax
Hobbyist Programmer
 
Broax's Avatar
 
Join Date: Jan 2005
Location: Porto, Portugal
Posts: 142
Rep Power: 4 Broax is on a distinguished road
Send a message via MSN to Broax
So... I've tried the ACSII enhanced iostream (or whatever it is), but it seams not to be fond of the "using namespace std" bit...

The code (with little comments):

#include <iostream> using namespace std

int main()
{
    cout << "blah" << "more blah" << "and even more blah" endl; //this would make this version 2.0 of the example given by Ooble which includes one extra blah! ;)
    /*so I seem to remember
    how to use everything
    so far, right?*/
    return 0;
}
//WRONG!!! I'm getting errors... :(

So this should make everything work, right? Wrong!

I'm getting the following errors from the (bloodshed) compiler:
Quote:
Line 21: [Warning] Extra tokens at end of #include directive
Line : In function "int main()".
Line 5: 'cout' undeclared (first use this function)
Line 5: (Each undeclared identifier is reported only once for each function it appears
Line 5: syntax error before ';' token
What I don't really get is why the first error is reported on line 21 when I've only done 12 lines of code...

Anyway, I've fidled around with the code but with no apparent success on fixing it. The only way for me to get everything running just fine is if I remove the "using name space std" (and adding the std:: to the proper cout part) bit and the "endl" bit from the "cout" line.

BTW, could you tell me what do STD and int (I know that int is integer, but I don't actually know what it is) stand for? It would make it easyer for me to memorize... I'm aiming at understanding programming instead of memorizing the strings of code... Although that I'll probably learn this in a future lesson, but it would make things easier now.

Thanks again for the help...
Broax is offline   Reply With Quote
Old Jan 17th, 2005, 9:50 AM   #16
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 8 Ooble is on a distinguished road
I obviously didn't explain that bit clearly:
#include <iostream>
using namespace std;
Sorry 'bout that.

And you need the << before endl as well.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Jan 17th, 2005, 11:11 AM   #17
Broax
Hobbyist Programmer
 
Broax's Avatar
 
Join Date: Jan 2005
Location: Porto, Portugal
Posts: 142
Rep Power: 4 Broax is on a distinguished road
Send a message via MSN to Broax
It works like a charm!

And thus our hero, broax, can proceed to the next level of enlightment (or however it is writen). But before he starts to learn of the wonders of variables, data types and constants, he would like to make two silly questions:

1st. is there any diference between cout << "something"; cout << "something else"; and cout << "something" << "something else";? If so what's would that diference be? And....

2nd. can cout be used to output other type of data stream like, for instance, images or does it stand for something like carachter output?

Anyway... I'll just take a long, long look at the next chapter of the tutorial and I'll post the results and/or doubts in here...

BTW, a code that you probably never seen:

#include <iostream>
using namespace std;

int main()
{
    cout << "Billy, watch out..." << " HERE I COME! >D" << endl;
    return 0;
}

This is open source, you can use it on all your apps... lol
Broax is offline   Reply With Quote
Old Jan 17th, 2005, 2:03 PM   #18
Xero
Hobbyist Programmer
 
Join Date: Dec 2004
Location: a cardboard box
Posts: 118
Rep Power: 4 Xero is on a distinguished road
Most people start off these days with either C++ or Java

www.cplusplus.com has a decent tutorial (basics)
Xero is offline   Reply With Quote
Old Jan 17th, 2005, 3:59 PM   #19
codetaino
Programmer
 
codetaino's Avatar
 
Join Date: Jan 2005
Location: Bayamon, Puerto Rico
Posts: 71
Rep Power: 4 codetaino is on a distinguished road
This is my first post in this thread so Hi is nice that you are learning to program. I love programming so I can assure you is a nice trip... It takes time to develop the logic behind it but after you get it... its all good... the answer to your questions ( as my knowledge goes ) are next:

Quote:
Originally Posted by Broax
1st. is there any diference between cout << "something"; cout << "something else"; and cout << "something" << "something else";? If so what's would that diference be? And....
In output there isnt. Just use the one you think is more readable.

Quote:
Originally Posted by Broax
2nd. can cout be used to output other type of data stream like, for instance, images or does it stand for something like carachter output?
No you can just use it to output text

I hope that the info helped you

codetaino

sorry for the errors my first language is spanish
__________________
"God bless u all" :)
codetaino is offline   Reply With Quote
Old Jan 17th, 2005, 4:28 PM   #20
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 8 Ooble is on a distinguished road
cout, I believe, either stands for character output or console output. Either way, it only prints text to the console. When you get to variables, you'll see the real power of the function:
cout << "You are " << age << " years old." << endl;
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:33 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC