C++常用庫函數

1.常用數學函數

#include <math.h>

函數原型 功能 返回值
int abs(int x) 求整數x的絕對值 絕對值
double arcos(double x) 計算arcos(x)的值 計算結果
double cos(double x) 求cos(x) 的值 計算結果
double exp(double x) 求e的x次方 計算結果
#include <iostream>
 #include <cmath>
 using namespace std;
 int main() {
   double e(double); 
   double x,sinh; 
   cout<<"enter x:";
   cin>>x; 
   sinh=(e(x)+e(-x))/2; 
   cout<<"sinh("<<x<<")="<<sinh<<endl;
   return 0; 
} double e(double x)
 {return exp(x);} 
2.常用字符串處理函數

#include <string.h>

函數原型 功能 返回值
void *memcpy(void *p1, const void *p2 size_t n) 存儲器拷貝,將p2所指向的共n個字節拷貝到p1所指向的存儲區中 目的存儲區的起始地址(實現任意數據類型之間的拷貝)
char *strcpy(char *p1, const char *p2) 將p2所指向的字符串拷貝到p1所指向的存儲區中 目的存儲區的起始地址
char *strcat(char *p1, const char *p2) 將p2所指向的字符串連接到p1所指向的字符串后面 目的存儲區的起始地址
int strcmp(const char *p1, const char *p2) 比較p1,p2所指向的兩個字符串的大小 兩個字符串相同,返回0;若p1所指向的字符串小于p2所指的字符串,返回負值;否則,返回正值
int strlen(const char *p) 求p所指向的字符串的長度 字符串所包含的字符個數(不包括字符串結束標志’\n’)
3.其他常用函數

#include <stdlib.h>

| 函數原型 | 功能 | 返回值 | 說明 |
| --------- |:-------------:| -----: | |
| void abort(void) | 終止程序執行| | 不能結束工作 |
| void exit(int) | 終止程序執行 | | 結束工作 |
|int atoi(const char *s) | 將s所指向的字符串轉換成整數| 整數值| |
| int rand(void) | 產生一個隨機整數 | 隨機整數 | |
|int system(const char *s) | 將s所指向的字符串作為一個可執行文件,并加以執行| | |
|max(a, b)|求兩個數的大數|大數|參數為任意類型|

4.實現鍵盤和文件輸入/輸出的成員函數

#include <iostream.h>

5.其他
C++的頭文件! 
#include <ctype.h>//字符處理 

#include <errno.h>//定義錯誤碼 

#include <float.h>//浮點數處理 

#include <fstream.h>//文件輸入/輸出 

#include <iomanip.h>//參數化輸入/輸出 

#include <iostream.h> //數據流輸入/輸出 

#include <limits.h> //定義各種數據類型最值常量 

#include <locale.h> //定義本地化函數 

#include <math.h> //定義數學函數 

#include <stdio.h> //定義輸入/輸出函數 

#include <stdlib.h> //定義雜項函數及內存分配函數 

#include <string.h> //字符串處理 

#include <strstrea.h> //基于數組的輸入/輸出 

#include <time.h> //定義關于時間的函數 

#include <wchar.h> //寬字符處理及輸入/輸出 

#include <wctype.h> //寬字符分類 


標準 C++ (同上的不再注釋) 

#include <algorithm> //STL 通用算法 

#include <bitset> //STL 位集容器 

#include <cctype> 

#include <cerrno> 

#include <clocale> 

#include <cmath> 

#include <complex> //復數類 

#include <cstdio> 

#include <cstdlib> 

#include <cstring> 

#include <ctime> 

#include <deque> //STL 雙端隊列容器 

#include <exception> //異常處理類 

#include <fstream> 
#include <functional> //STL 定義運算函數(代替運算符) 

#include <limits> 

#include <list> //STL 線性列表容器 

#include <map> //STL 映射容器 

#include <iomanip> 

#include <ios> //基本輸入/輸出支持 

#include <iosfwd> //輸入/輸出系統使用的前置聲明 

#include <iostream> 

#include <istream> //基本輸入流 

#include <ostream> //基本輸出流 

#include <queue> //STL 隊列容器 

#include <set> //STL 集合容器 

#include <sstream> //基于字符串的流 

#include <stack> //STL 堆棧容器 

#include <stdexcept> //標準異常類 

#include <streambuf> //底層輸入/輸出支持 

#include <string> //字符串類 

#include <utility> //STL 通用模板類 

#include <vector> //STL 動態數組容器 

#include <cwchar> 

#include <cwctype> 


最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容