除非特别说明,所在的命名空间均是:标准命名空间,也即std;
| stuff | header | 说明 |
|---|---|---|
| ifstream ofstream fstream | <fstream> | 文件流 in>> out << |
| istringstream ostringstream stringstream | <sstream | 字符串流 |
| <shared_ptr> <unique_ptr> | <memory> | <memory>是标准命名空间的头文件 <boost\shared_ptr.hpp>头文件,命名空间为boost也有智能指针的定义 |
| pair | <utility> | |
| complex | <complex> | |
| numeric_limits | <limits> | |
| accumulate | <numeric> | |
| ptrdiff_t | <crtdef.h> | |
| size_t | <cstddef> | |
| unordered_map unordered_mulitmap | <unordered_map> | |
| unordered_set unordered_multiset | <unordered_set> | |
| is_pointer(模板结构体) is_integral(模板结构体) | <type_traits> | |
| ifstream ofstream | <fstream> | |
| pair | <utility> | |
| tuple | <tuple> | |
| for_each | <algorithm> | |
| getline | <string> | while(std::getline(in, str, ‘\n’)){…} 第三个参数(分隔符)的类型为char,而不是string |
| setw | <iomanip> | cout << setw(10) << left << … |
接口
没有pair_size和pair_element,pair对象也统一交由tuple_like接口(tuple_size、tuple_element)管理。
-
tuple_size:返回参数个数,
-
tuple_element:返回每一位上的类型,第一个模板参数为非类型模板参数
typedef std::tuple<int, float, std::string> TupleType;
cout << std::tuple_size<TupleType>::value << endl;
std::tuple_element<2, TupleType>::type s("hello world");
1. C 头文件
| stuff | header | 说明 |
|---|---|---|
| malloc | <stdlib.h> | |
| exit | <cstdlib.h> | |
| strlen | <string.h> | <string>也给出了该函数的实现 自然无需在std的命名空间中 |
| typeid | <typeinfo> | 但不在std标准命名空间中 |
| getch()/_getch() | <conio.h> | Console Input/Output(控制台输入输出)的简写 |
2. C++ 头文件
| stuff | header | 说明 |
|---|---|---|
| min/max | algorithm | std |
3. cstdlib ⇒ exit()
void exit(int code);
错误码主要有:
#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1
std::ifstream ifs(filename);
if (!ifs.good())
{
std::cerr << "cannot open the input file \"" << filename << "\"" << std::endl;
exit(EXIT_FAILURE);
}
4. typeid
int fputs(const char*, FILE* );
为什么可将标准输入输出(stdin/stdout)赋值给fputs的第二个参数,可见stdin/stdout的真实数据类型应是FILE*,使用typeid一试便知:
printf("%s\n", typeid(stdout).name());
printf("%s\n", typeid(FILE*).name());
5. toupper/tolower
所在的头文件 :
#include <ctype.h> // C
#include <cctype> // C++
函数声明:
int toupper(int c);
使用:
char(toupper('a')) ⇒ 'A'
本文介绍了C++标准库中的关键组件,包括文件流、字符串流、智能指针等,并详细解释了它们的用途和使用方式。此外还讨论了一些常用的算法、数据类型以及类型检查方法。

813

被折叠的 条评论
为什么被折叠?



