不管哪种语言调用接口都需要引入相应的包,比如C或C++中调用Windows的接口
需要include "windows.h"的头文件,才可以调用系统的接口
如果第三方或是自已提供的接口,则同样包含头文件是首先要做的工作。换种理解,因为接口的定义就包含在这些头文件中,如果不引入将提示未定义的函数。
接着下一步进行调用,API成千上万个,有目的的使用接口是关键,这些接口在头文件中都有相应的名称,比如system函数
如果你调用第三方的接口,比如天气预报,同样会有一个头文件,里面有大量的接口,看官方文档说明进行调用,而那些函数名称也都是第三方起的,随便举个例子可能叫get_weather_report(location)
调用API接口其实只是一个概念,在开发中无数次要重复的一个小小的过程。
#include <windows.h>这样就可以条用api文件了;如果只是关机的话下面的代码你可以试试#include<stdio.h>
#include<dos.h>
#include<stdlib.h>
void main()
{
char shut[8]
char b[81]
printf("Hello, Welcome to the TC automatic shutdown procedures\n")
printf(" Watermelon production\n")
printf("Please enter your desired automatic shutdown of time:")
scanf("%s",shut)
sprintf(b,"at %s shutdown -s",shut)
system(b)
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)