• (2 Pages)
  • +
  • 1
  • 2

An Introduction to Libraries (A Beginner's Guide) Rate Topic: ***** 4 Votes

#1 RandomlyKnighted  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 117
  • View blog
  • Posts: 1,370
  • Joined: 14-January 10

Posted 25 September 2010 - 08:47 PM

*
POPULAR

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:

#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.

This post has been edited by JackOfAllTrades: 15 July 2011 - 10:19 AM


Is This A Good Question/Topic? 12
  • +

Replies To: An Introduction to Libraries (A Beginner's Guide)

#2 Plitum  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 18-November 10

Posted 22 November 2010 - 02:47 PM

Simple but effective.Thanx.
Was This Post Helpful? 0
  • +
  • -

#3 kpkiran  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 25-November 10

Posted 25 November 2010 - 12:01 PM

very nice lesson
Was This Post Helpful? 0
  • +
  • -

#4 ecknowledgy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 04-February 11

Posted 04 February 2011 - 11:59 AM

This is helpful. I like your approach.Thank you for taking the time to post this analogy.
Was This Post Helpful? 0
  • +
  • -

#5 RandomlyKnighted  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 117
  • View blog
  • Posts: 1,370
  • Joined: 14-January 10

Posted 14 February 2011 - 01:30 PM

I'm around friends all the time that struggle to understand how programming works. Through helping them I've learned that keeping things simple like I tried to do above in my tutorial really helps students the most.
Was This Post Helpful? 2
  • +
  • -

#6 PexMech  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 6
  • Joined: 24-February 11

Posted 24 February 2011 - 06:29 PM

Thanks mate for reading your guide.

:blush: In fact here's one who wants to understand the concept.

Two simple question's pops up in my mind:

  • In write the code it doesn't need more than a text editor program. But what kind of software would be best to use for a beginner if searching for something that is able to handle most of the usual things?
  • Lets say I'm looking for create a Windows utility app in manage specific settings in the os. Is there some sort of references or basic guides that explain in how to set it up or do we only use these libraries for the job?

Was This Post Helpful? 1
  • +
  • -

#7 maede_h  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 26-February 11

Posted 05 March 2011 - 07:37 AM

thanks a lot. it was helpful :)
Was This Post Helpful? 0
  • +
  • -

#8 RandomlyKnighted  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 117
  • View blog
  • Posts: 1,370
  • Joined: 14-January 10

Posted 05 March 2011 - 12:03 PM

@maede_h Your welcome. I'm glad that I could help!

@PexMech Yes, you could use something like Notepad++ to write your code. Just remember to save it as a cpp file.

I'm a little confused on what you mean in your second question. Could you try explaining it a little differently?

This post has been edited by RandomlyKnighted: 05 March 2011 - 12:04 PM

Was This Post Helpful? 0
  • +
  • -

#9 hulla  Icon User is offline

  • Writing Lines


Reputation: 49
  • View blog
  • Posts: 732
  • Joined: 05-March 11

Posted 05 March 2011 - 07:36 PM

View PostPexMech, on 24 February 2011 - 06:29 PM, said:

Thanks mate for reading your guide.

:blush: In fact here's one who wants to understand the concept.

Two simple question's pops up in my mind:

  • In write the code it doesn't need more than a text editor program. But what kind of software would be best to use for a beginner if searching for something that is able to handle most of the usual things?
  • Lets say I'm looking for create a Windows utility app in manage specific settings in the os. Is there some sort of references or basic guides that explain in how to set it up or do we only use these libraries for the job?

________________________________________________________________

Yeah I agree with point one. Thanks
Was This Post Helpful? 0
  • +
  • -

#10 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6066
  • View blog
  • Posts: 23,526
  • Joined: 23-August 08

Posted 06 March 2011 - 05:41 AM

If you're developing software for Windows, your first resource should be MSDN.
Was This Post Helpful? 1
  • +
  • -

#11 PlasticineGuy  Icon User is offline

  • mov dword[esp+eax],0
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,436
  • Joined: 03-January 10

Posted 16 June 2011 - 07:37 AM

I actually think including the whole namespace std is a bad idea for more experienced programmers. The reason being, you are likely to at some point create a function with the same name as one in the standard library, causing errors (in fact this is why namespaces exist in the first place).
Was This Post Helpful? 0
  • +
  • -

#12 hulla  Icon User is offline

  • Writing Lines


Reputation: 49
  • View blog
  • Posts: 732
  • Joined: 05-March 11

Posted 28 June 2011 - 06:29 AM

View PostPlasticineGuy, on 16 June 2011 - 07:37 AM, said:

I actually think including the whole namespace std is a bad idea for more experienced programmers. The reason being, you are likely to at some point create a function with the same name as one in the standard library, causing errors (in fact this is why namespaces exist in the first place).


Yeah and another thing with namespaces is that you can't "undeclare" a namespace. An example is if you have a code (with 1 function) and are using namespace std, then you cannot "unuse" it for a certain instruction which is in a different namespace. :sarcasm:
Was This Post Helpful? 0
  • +
  • -

#13 Jianju  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 15
  • Joined: 11-July 11

Posted 13 July 2011 - 09:33 PM

Good one, thanks!

This post has been edited by Jianju: 13 July 2011 - 09:36 PM

Was This Post Helpful? 0
  • +
  • -

#14 stackoverflow  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 165
  • View blog
  • Posts: 545
  • Joined: 06-July 11

Posted 14 July 2011 - 07:22 AM

I am not sure if your code segment was glitched but I only see include <iostream>. It should be,

#include <iostream>


Good idea for a tutorial--

MOD EDIT: Fixed
Was This Post Helpful? 0
  • +
  • -

#15 ipushmycar  Icon User is offline

  • D.I.C Regular

Reputation: 86
  • View blog
  • Posts: 390
  • Joined: 29-August 10

Posted 14 July 2011 - 08:00 AM

Nice tutorial. I would suggest proof reading your post. There were parts that I needed to reread to understand what you were trying to say.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2