Post by RandomlyKnighted on Aug 11, 2011 10:48:37 GMT -5
A Few Words By The Author
Note: In this lesson, it is assumed that you already know how to open and create a C++ project within your IDE. It is also assumed that you know how to create a .cpp file in order to write your code.
I'd just like to begin by saying that this lesson was designed to be a tutorial to people who have a hard time understanding large concepts. I hope that this tutorial is easy for every person to understand. So let's begin!
The Tutorial
We've all been there. You're sitting in class and the next thing you know your computer science teacher starts talking about libraries. He's not talking about the library where you check out book. In the world of computers, libraries mean something completely different.
When you hear your teacher say library or libraries, he/she is actually referring to a core part of any programming language. See there are programmers all over the world that are creating code and putting it into a form that we call a library. The library basically shortens the amount of code that you need to make your program to work.
Let's use an example: You have just fixed your first 500-word English paper and you tell Microsoft Word that to print your paper. Well if you were making a program and you wanted to let the person that will be using it to have the ability to print something then you wouldn't want to type 3000 lines of code just so they can print something. Instead you import a library into your program and it does the work for you. Now you just write a few lines of code and you're done. There are hundreds of libraries available for you to use, it's just a matter of finding the one that does what you need.
So now I bet you're going, "Teach me how to import a library. I want to learn how to do this the easy way!" Come on, we all know you're thinking it. Ok, well here you go! The basic library in C++ is called the iostream, which is a part of the standard C++ library. Your teacher will go into more detail about all the iostream library has to offer. Let's just focus on how to import it into your program.
At the top of your program, add the line of code below:
That's all there is to it. Now your program isn't going to work with that one line of code, but that's all you need to import the iostream. One last thing for this lesson: in C++ Programming you have something called a namespace. A namespace is sort of another form of a library; however, you do not have to remember multiple namespaces like you do libraries. All you have to do is add the line below:
You're good to go. You now have added your first library and namespace to your program. I know I said that was the last thing for this lesson, but I just want to let you know something important. In order to take full advantage of the libraries, you must import them into EVERY program that you write in C++. Every program that you will write is different; therefore, in one program you might use the iostream and cmath libraries but then in another program you might only use the iostream library. Although, you will use the Standard Namespace (using namespace std;) in every one of your programs. That never changes.
Well I hope you enjoyed your first lesson.
Note: In this lesson, it is assumed that you already know how to open and create a C++ project within your IDE. It is also assumed that you know how to create a .cpp file in order to write your code.
I'd just like to begin by saying that this lesson was designed to be a tutorial to people who have a hard time understanding large concepts. I hope that this tutorial is easy for every person to understand. So let's begin!
The Tutorial
We've all been there. You're sitting in class and the next thing you know your computer science teacher starts talking about libraries. He's not talking about the library where you check out book. In the world of computers, libraries mean something completely different.
When you hear your teacher say library or libraries, he/she is actually referring to a core part of any programming language. See there are programmers all over the world that are creating code and putting it into a form that we call a library. The library basically shortens the amount of code that you need to make your program to work.
Let's use an example: You have just fixed your first 500-word English paper and you tell Microsoft Word that to print your paper. Well if you were making a program and you wanted to let the person that will be using it to have the ability to print something then you wouldn't want to type 3000 lines of code just so they can print something. Instead you import a library into your program and it does the work for you. Now you just write a few lines of code and you're done. There are hundreds of libraries available for you to use, it's just a matter of finding the one that does what you need.
So now I bet you're going, "Teach me how to import a library. I want to learn how to do this the easy way!" Come on, we all know you're thinking it. Ok, well here you go! The basic library in C++ is called the iostream, which is a part of the standard C++ library. Your teacher will go into more detail about all the iostream library has to offer. Let's just focus on how to import it into your program.
At the top of your program, add the line of code below:
#include <iostream>
That's all there is to it. Now your program isn't going to work with that one line of code, but that's all you need to import the iostream. One last thing for this lesson: in C++ Programming you have something called a namespace. A namespace is sort of another form of a library; however, you do not have to remember multiple namespaces like you do libraries. All you have to do is add the line below:
using namespace std;
You're good to go. You now have added your first library and namespace to your program. I know I said that was the last thing for this lesson, but I just want to let you know something important. In order to take full advantage of the libraries, you must import them into EVERY program that you write in C++. Every program that you will write is different; therefore, in one program you might use the iostream and cmath libraries but then in another program you might only use the iostream library. Although, you will use the Standard Namespace (using namespace std;) in every one of your programs. That never changes.
Well I hope you enjoyed your first lesson.