質問

My question is "when we come across a new function, how can we figure out what is the minimum header file/library to include?

In other words, is there a systematic way to figure out the required header/library for a certain function?

To clarify:

I googled and found ofstream to be handy for output I/O. I needed to include <fstream> to be able to use ofstream. how can I determine these two libraries and how to figure out the minimum required one? (well in this case, I googled again! or obviously I could search the filesystem for any file .h or .soor .cpp or ... that define this function )

役に立ちましたか?

解決

Reading the documentation is the preferred way.
Searching the filesystems for the function name way too often leads astray - there are many headers that rely on code in a file that includes it in turn.

The cppreference site is a pretty good resource on the standard.

For platform specifics:
If you're on Windows, MSDN tells you exactly which header and library to include.
Linux and Unixes have their man pages.
OS X has the XCode documentation and man pages.

他のヒント

Well you have answered your own question. Either google it or check the API documentation, they should mention what is to be included. For example "man strcpy" tells me that I need to include #include <string.h>.

Additionally, you can also try to understand the relationship among the APIs. For example, fstream provides ofstream and ifstream, so including fstream will help in that case.

When it comes to standard C or C++, I usually use cppreference to find which header file is related with what I want to use.

If it is Unix-related, then the man pages are my friend.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top