Skip to main content
GameDev.net gamedev.net
🔒 Locked

What do all these things do???

Started by Kalibr Jan 8, 2006 at 4:54 PM 17 replies 2.1k views
Original Post
Kalibr
Kalibr
At the start of the holidays I decided to get into programming. I bought a book on C++ from Herbert Schildt. I also used the bloodshed Dev-C++ (www.bloodshed.net)programming as a compiler and editor. The problem I have is that I have absolutely NO idea of what the things I use do, what theyr'e for and various other details... I'm basically asking what all these things are for, as I'm now wanting to make my own apps. my main problems are the #include , the #include , #include . I get so many errors when I exclude them that I don't have a way to single out what they do. In closing I need help.
Erondial
Erondial
What you're doing when you include those files basically means in plain english

Take the code from C:\Program Files\Dev-Cpp\include\ and stick it in at the top of my file.

iostream handles all the cout and cin and interactions with the console, it means Input/Output Stream
cmath handles all complex math functions (cos,sin,tan,asin,M_PI,etc..), it means C Math.
cstlib handles pretty much everything else, it means C Standard Library.

using namespace std means that you're telling the compiler to use the standard namespace. This is not required for most programs after the console ones. A namespace (as I understand it) is just used to differentiate between functions and objects which have the exact same names, but preform different operations.

int main(int argv, char** argv)is your entrypoint. Your program starts from here.

I think that's it for your basic program.
furby100
furby100
On namespaces:

A namespace is something that contains functions and variables, and has a name. Things you might want to use in the standard library are in the std namespace, so you write std:: before them. For instance if you want to write to the screen, you'd #include and use the std::cout class. If you write using namespace std;, this means you don't have to write the std:: before anything that's in the std namespace in order to refer to it, so you can just write cout. If you had some other namespace called foo, with a class in it called Fred, then normally you'd have to write foo::Fred to access Fred, but if you wrote using namespace foo; then you could refer to Fred just as Fred.
LessBread
LessBread
Quote:
Original post by Kalibr
my main problems are the #include , the #include , #include . I get so many errors when I exclude them that I don't have a way to single out what they do.


Those lines direct the preprocessor to "include" those header files in the file slated for compilation. To examine preprocessor output, open a command prompt (aka dos box) to your Dev-Cpp installation directory, then move to the /bin directory. On my computer, "C:\Dev-Cpp\bin". The "-E" argument tells the compiler to "Preprocess only; do not compile, assemble or link". For example

C:\Dev-Cpp\bin>gcc -E somefile.cpp

As a general tip, there are a host of command line arguments to gcc. Pipe the
command line help to a file for easier review of the options. For example

C:\Dev-Cpp\bin>gcc -v --help > gcc_help.txt

If you're wanting to know about those header files in particular, open them up in a text editor and read them.

iostream contains the definitions for the standard stream objects. You need this file to get input from the keyboard or to output to the console. cout and cin come from this file.

cstdlib contains the prototypes for a number of standard defined functions. These are general purpose functions, malloc, calloc, free, atoi, atof, and so on.

cmath contains the prototypes for mathematics functions, abs, cos, sin, exp, pow, log and so on.

"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
darookie
darookie
You should consider not starting programming with C++ and use another programming language that is more beginner-friendly.
If you really want to start with C++, take a look at Accelerated C++ or the free online books Thinking In C++ Vol.1 and 2 by Bruce Eckel.

C++ is has a steep learning curve and is hard to master due to its complexity.
The mentioned books, however, will answer your questions.

Good luck and happy programming,
Pat.
jflanglois
jflanglois
This is a little off-topic, but I'm surprised that no one has yet mentioned that Visual C++ 2005 Express Edition (as an alternative to Dev-C++) is a free download for a while yet, and is a worthwhile download if only for it's superb debugger.


jfl.
furby100
furby100
#include works similarly to what #include used to do in C and old C++, except it's supposed to put all the functions there into the std namespace, and may also automatically put them in the global namespace too.
cignox1
cignox1
Quote:
Original post by jflanglois
This is a little off-topic, but I'm surprised that no one has yet mentioned that Visual C++ 2005 Express Edition (as an alternative to Dev-C++) is a free download for a while yet, and is a worthwhile download if only for it's superb debugger.


jfl.


The OP asked what #include does, so I suppose a good debugger is not so urgent ;-)

Well, other posts answered your question. Anyway, you should be able to find all those informations in the book. I've read 2 book of shildt, and (IIRC) both of them explained that (not really two masterpieces, though).

Good luck!
Kalibr
Kalibr
First off, I apologize for diverting the topic, but Darookie suggested that I start with an easier language, which is the easiest to learn and get compilers for etc..
Keep in mind that I'm a penniless student trying to save upfor a upgrade on my current PC. Also, would there be free online tutorials for this easier language?
Would anyone who knows links to said sites please post them, your help would be greatly appreciated.
Also, I would like to thank the other posters for their contributions.
Kalibr
Roboguy
Roboguy
Quote:
Original post by Kalibr
First off, I apologize for diverting the topic, but Darookie suggested that I start with an easier language, which is the easiest to learn and get compilers for etc..
Keep in mind that I'm a penniless student trying to save upfor a upgrade on my current PC. Also, would there be free online tutorials for this easier language?
Would anyone who knows links to said sites please post them, your help would be greatly appreciated.
Also, I would like to thank the other posters for their contributions.
Kalibr


Python is a good place to start. Also, here are some Python links I've collected, which you might want to look at.
Cocalus
Cocalus
Python is an excellent beginners language (And is used professionally to some degree). There's a decent beginners book, Here. There may be better books, that's just the only that I've read (It's looks pretty good for someone with no programming experience). Note that the C++ example in it has several bugs (The kind of bugs that imply that the author has no experience with C++).

Also Python is really different from C++, just so your warned.
Kalibr
Kalibr
Quote:
Original post by Cocalus
Python is an excellent beginners language (And is used professionally to some degree). There's a decent beginners book, Here. There may be better books, that's just the only that I've read (It's looks pretty good for someone with no programming experience). Note that the C++ example in it has several bugs (The kind of bugs that imply that the author has no experience with C++).

Also Python is really different from C++, just so your warned.


This has scared me to the depths of my soul ...
Will this help me in genral programming for the future?
also, does this mean that I'm going to have to re-learn C++ when I'm done?
I'm scared now.
pulpfist
pulpfist
C++ didnt scare me until I started posting here at GameDev. As a beginner you will be fine using C++ in my oppinion. Dont worry if your programs has a memory leak here and there, just be aware that it might. If you are the thorough and patient type, I think youll be fine. If your inpatient, and want advanced things to work without a sweat, Python, Java or Visual Basic might be a better choise.

Quote:

Will this help me in genral programming for the future?

Absolutely.
Learning the syntax of a language is much like learning the alphabet. Its not the hard part.
Learning the words, and how to build sentences is the challenge, and that is pretty much the same in all the most common programming languages.
MrTufty
MrTufty
I'll second that.

Programming in C++ isn't that hard to learn, it just takes patience - it's the learning how to use it most effectively that takes the longest.

Once you've learned the main commands - for example, now you know what #include means - it all quickly builds up from there, and you can move onto more complicated things. Just don't try and make a graphical application just yet, take your time to get the basics down first - take it from someone who knows, jumping in at the deep end is a good way to learn how to drown.

But seriously, you should consider Visual C++ Express Edition. It'll probably help you :) I've never liked Dev-C++ though.
C plus noob
C plus noob
Quote:
Original post by darookie
You should consider not starting programming with C++ and use another programming language that is more beginner-friendly.
If you really want to start with C++, take a look at Accelerated C++ or the free online books Thinking In C++ Vol.1 and 2 by Bruce Eckel.

C++ is has a steep learning curve and is hard to master due to its complexity.
The mentioned books, however, will answer your questions.

Good luck and happy programming,
Pat.


i woiuld hardly call C++ complex, it takes time, but i started when i was 12 years old.

C plus noob
C plus noob
i added your email you have in your profile to my msn i can help you there.
Kalibr
Kalibr
ok, lol, I need a helping hand. Thanks
Roboguy
Roboguy
Quote:
Original post by C plus noob
Quote:
Original post by darookie
You should consider not starting programming with C++ and use another programming language that is more beginner-friendly.
If you really want to start with C++, take a look at Accelerated C++ or the free online books Thinking In C++ Vol.1 and 2 by Bruce Eckel.

C++ is has a steep learning curve and is hard to master due to its complexity.
The mentioned books, however, will answer your questions.

Good luck and happy programming,
Pat.


i woiuld hardly call C++ complex, it takes time, but i started when i was 12 years old.


C++ is relatively complex, compared to most high-level languages.
Kalibr
Kalibr
Thanks for all your input people. If no-one else has anything to say on this topic, then I bid you all happy coding!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.