跳转到内容
新建笔记

常用库

库名及主要功能代码示例
#include <iostream> - 输入输出库std::cout << "Hello, World!" << std::endl;
#include <vector> - 动态数组容器std::vector<int> v = {1, 2, 3};
#include <string> - 字符串处理std::string str = "Hello";
#include <algorithm> - 算法库std::sort(v.begin(), v.end());
#include <map> - 有序键-值映射std::map<int, std::string> m = {{1, "one"}, {2, "two"}};
#include <unordered_map> - 无序键-值映射std::unordered_map<int, std::string> um = {{1, "one"}, {2, "two"}};
#include <set> - 有序集合std::set<int> s = {1, 2, 3};
#include <unordered_set> - 无序集合std::unordered_set<int> us = {1, 2, 3};
#include <list> - 链表容器std::list<int> lst = {1, 2, 3};
#include <stack> - 栈std::stack<int> st; st.push(1);
#include <queue> - 队列std::queue<int> q; q.push(1);
#include <fstream> - 文件输入输出std::ofstream file("example.txt"); file << "Hello";
#include <ctime> - 时间操作std::time_t t = std::time(nullptr);
#include <iomanip> - 格式化输入输出std::cout << std::fixed << std::setprecision(2) << 3.14159;
#include <thread> - 多线程管理std::thread t([] { /* ... */ }); t.join();
#include <cmath> - 数学函数double result = std::sin(1.0);
#include <cstddef> - 通用定义std::size_t size = 10;
#include <bitset> - 位集合操作std::bitset<8> b(42);