一、数学函数(头文件 <cmath>

1. abs() - 绝对值函数

原型 说明
int abs(int n) 整数绝对值
double fabs(double x) 浮点数绝对值(C 风格)
std::cout << abs(-5);       // 5
std::cout << fabs(-5.6);    // 5.6

2. pow() - 幂函数

double pow(double base, double exp);
std::cout << pow(2, 3);  // 8

3. sqrt() - 平方根

double sqrt(double x);  // 返回 √x

4. ceil() / floor() / round() - 向上、向下、四舍五入取整

ceil(3.2);    // 4
floor(3.7);   // 3
round(3.5);   // 4

数学函数表格

二、字符串相关函数(<string>

1. std::string::find()

size_t find(const string& substr, size_t pos = 0);
std::string s = "hello world";
s.find("world");   // 返回 6

2. std::string::substr()

std::string substr(size_t pos = 0, size_t len = npos);
std::string s = "abcdef";
s.substr(2, 3);  // "cde"

3. std::getline()