简体   繁体   English

C:我怎么知道我正在使用的函数需要什么标题?

[英]C: How can I know what header do I need for the functions I am using?

Example program in C (without headers): C中的示例程序 (无标题):

int main()
{
printf("\nHello World\n");
}

How can I know what include header (example: #include <stdio.h> ) should I prepend? 如何才能知道包含标题的内容 (例如: #include <stdio.h> )?

Considering that you might not be able to search online (which would be the obvious choice most of the time I guess) and that you are on a linux machine you could also search for it in the man pages. 考虑到你可能无法在线搜索(这是我猜的大部分时间都是明显的选择)并且你在linux机器上也可以在手册页中搜索它。
To search inside the man pages you can use man -k {search term} 要在手册页内搜索,您可以使用man -k {search term}

For example printf 例如printf

$ man -k printf 
asprintf (3)         - print to allocated string
dprintf (3)          - formatted output conversion
fprintf (3)          - formatted output conversion
fwprintf (3)         - formatted wide-character output conversion
printf (1)           - format and print data
printf (3)           - formatted output conversion
snprintf (3)         - formatted output conversion
sprintf (3)          - formatted output conversion
swprintf (3)         - formatted wide-character output conversion
vasprintf (3)        - print to allocated string
vdprintf (3)         - formatted output conversion
vfprintf (3)         - formatted output conversion
vfwprintf (3)        - formatted wide-character output conversion
vprintf (3)          - formatted output conversion
vsnprintf (3)        - formatted output conversion
vsprintf (3)         - formatted output conversion
vswprintf (3)        - formatted wide-character output conversion
vwprintf (3)         - formatted wide-character output conversion
wprintf (3)          - formatted wide-character output conversion
XtAsprintf (3)       - memory management functions

$ man 3 printf
PRINTF(3)                                                                                  Linux Programmer's Manual                                                                                 PRINTF(3)

NAME
       printf, fprintf, dprintf, sprintf, snprintf, vprintf, vfprintf, vdprintf, vsprintf, vsnprintf - formatted output conversion

SYNOPSIS
       #include <stdio.h>

       int printf(const char *format, ...);
       int fprintf(FILE *stream, const char *format, ...);
...

As has been mentioned in comments, you can use the search feature on https://en.cppreference.com/w/c/header . 正如评论中所述,您可以使用https://en.cppreference.com/w/c/header上的搜索功能。

Just make sure you select the C version of the function. 只需确保选择该功能的C版本。

在此输入图像描述

And the header you need to include is listed at the top of the page. 您需要包含的标题列在页面顶部。

在此输入图像描述

使用它作为参考C库引用 ,让你的代码工作使用它

#include <stdio.h>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 需要知道如何在 c 中按空格解析单词。 还需要知道我是否正确分配内存? - Need to know how to parse words by space in c. Also need to know if I am allocating memory correctly? 我如何知道可执行文件中有哪些功能? - How Can I know what functions are there in an executable file? 我需要知道我是否正确使用了getline - I need to know if I am using getline correctly 如何知道我使用的是哪个版本的 C 语言? - How to know which version of C language I am using? 关于C ++编译器,我在哪里学习“我需要了解的内容”? - Where do I learn “what I need to know” about C++ compilers? 在CI中出现细分错误,我不知道为什么 - In C I am getting segmentation fault, i do not know why 如果c ++函数需要其他库,如何编译“ c语言的c ++函数”? - How do I compile “c++ functions from c” if c++ functions need other libraries? 我如何知道我是否正在使用Windows API使用ARM? - How do I know if I am using ARM using Windows API? 我怎么知道何时应该释放库函数返回的C语言中的字符串? - How do I know when I ought to free strings in C returned by library functions? C libpcap:如何查看标头/数据包中的内容? - C libpcap: How do I see what's in the header/packet?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM