跳轉到內容

C++ 程式設計/標頭檔案

來自華夏公益教科書,開放的書籍,開放的世界

C 標準標頭檔案

[編輯 | 編輯原始碼]

這些標準標頭檔案定義了最初在 C 程式語言中定義的函式。它們使將 C 程式碼移植到 C++ 變得更加容易。

這些只是 C++ 標準標頭檔案 中的少數幾個。

#include <cctype>

int isalnum(int c);
int isalpha(int c);
int iscntrl(int c);
int isdigit(int c);
int isgraph(int c);
int islower(int c);
int isspace(int c);
int isprint(int c);
int isupper(int c);

C++ 程式設計師幾乎從未使用過這些 cstring 函式,我們使用 字串類 來代替。

#include <cstring>

size_t strlen(char* str);
char* strcpy(char* dest, char* src);
char* strncpy(char* dest, char* src, size_t length);
int strcmp(const char* s1, const char* s2);
int strncmp(const char* s1, const char* s2, size_t length);
char* strtok(char* str, const char* delim);
char* strchr(const char* str, int c);
char* strstr(const char* str, const char* within);
#include <ctime>

clock_t clock(void);
double difftime(time_t t1, time_t t0);
time_t mktime(struct tm *timeptr);
time_t time(time_t *timer);
char *asctime(struct tm *timeptr);
char *ctime(const time_t *timer);
struct tm *gmtime(const time_t *timer);
struct tm *localtime(const time_t *timer);
size_t strftime(char * s, size_t maxsize, const char * format, struct tm * timeptr);
clock_t clock(void);
double difftime(time_t t1, time_t t0);
time_t mktime(struct tm *timeptr);
time_t time(time_t *timer);
char *asctime(struct tm *timeptr);
char *ctime(const time_t *timer);
struct tm *gmtime(const time_t *timer);
struct tm *localtime(const time_t *timer);
size_t strftime(char * s, size_t maxsize, const char * format, struct tm * timeptr);

這些 cmath 函式在許多物理模擬中被大量使用,例如逼真的電子遊戲、有限元分析等。

 #include <cmath>

有關 標準 C 庫數學C 程式設計 華夏公益教科書 進一步數學頁面 的更多詳細資訊,請參見該書部分。

此標頭檔案列出了所有 C++ 中使用的基本資料型別 的最大值和最小值。

 #include <climits>

對應於 C 語言中的 "limits.h"。

請參見 C 程式設計 華夏公益教科書頁面,瞭解有關 C99 參考 及其 標準標頭檔案參考表 的資訊。

華夏公益教科書