Sentiment through the external dependencies of C + +

Source: Internet
Author: User

External dependencies are here (in fact it's easy to ignore)! But it can see a lot of hidden things!

What is it that can explain the problem?

See the right program source code directly using System ("pause");

And the small partners who have learned the C language should know that to use this function, it is necessary to introduce stdlib.h, namely:

#include <stdlib.h>

But why not introduce it here and use it?

In fact, there is no violation of the "function call must have function body support" This objective law. It's just that it's hidden. Right here:

Don't you feel weird? has been introduced! But it does not contain it, which is the result of "file dependency".

In fact, writing different programs will use different functions, you need to include different files. But at this point, if the code in the file requires other files to be loaded first, there is a dependency (which is often seen when compiling software in Linux, it is software dependencies, so the Yum installation software is the appearance of the way)

Let's look at the list of dependent files for different programs:

1:

No files are introduced here, so the "external dependencies" directory is empty.

Now instead:

After compiling, you can see the stdio.h in the dependent directory, and also involve other dependent files that will allow the code inside the stdio.h to run properly. So there's a whole bunch.

Continue to read:

As you can see, the stdio.h,stdlib.h that you manually include are introduced, along with other dependent files.

Then change to:

Look after opening:

Visible, the file name it can take. h suffix, can also take no suffix, is a file, it is open on the line, but also with the C language inside the head file, can be a glance to know is C + + unique characteristics of the file.

As you can see, although you only introduce the iostream file, it requires other dependent files so that the stdio.h,stdlib.h is brought in.

So you can use system directly ("pause");

Try opening iostream this file:

As you can see, this file does contain IStream, only to be introduced.

At the same time, you can see that string.h is also included in the C language of the kind of processing string usage. So after C + + does not want to use this string.h inside of things, you need to introduce a string file, in order to use the string type (because the string file is not included in, so it is included).

Attention:

Because of the inclusion and dependencies between the files are very fine, but also randomly interspersed, so listed a list of easy to see, it actually does not have this obligation, so you have compiled after the list to you see is already good, so ask not too high. So: Remember to look again after compiling. If it is not listed, turn off the software again and turn the compiler back on to see it. Why is that? Because it only to compile the time to know what to rely on, and the relevant code has been taken to the compilation of the results of the executable file, the software this place just give you a feedback message, so lag even do not give you a list to see, is also possible. So if it's not listed, then shut down the software again, recompile and run it and see it (that's the effect I'm testing anyway).

Sentiment through the external dependencies of C + +

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.