本文档说明当前平台对 C++ 语言的支持范围和限制。
请在使用时注意以下规则,避免使用不兼容的语法特性。
支持以下基础类型的声明和使用:
char
, string
, bool
, int
, float
, double
示例:
支持以下容器及其嵌套形式:
容器类型 | 示例 |
---|---|
vector<T> | vector<int> nums3 |
vector<vector<T>> | 二维动态数组 |
map<T1, T2> | map<int, string> |
unordered_map<T1,T2> | 哈希表 |
queue<T> | 队列 |
set<T> | 集合 |
unordered_set<T> | 集合 |
stack<T> | 栈 |
约束条件:
map
/unordered_map
的 Key 必须为基础类型(char/string/bool/int/float/double
)- 容器嵌套深度最多支持到 2层(如
vector<vector<int>>
)
可直接使用以下预定义结构:
- 代码中必须包含以
int
为返回值的main
函数, 并显式返回int
- 支持函数和类方法(类的静态方法除外)
- 支持 Lambda 表达式,但必须 显式捕获变量(如
[&]{}
) - 已预先包含常用头文件(如
<vector>
,<algorithm>
等),无需手动引入
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <utility>
类别 | 示例 | 备注 |
---|---|---|
头文件引入 | #include <sstream> | 已内置常用库 |
静态方法 | MyClass::staticFunc() | 不支持类静态方法 |
匿名函数(无 & ) | [](\){ ... } | 必须写成 [&](\){ ... } |
stringstream | ss << "text" | 改用 to_string 等替代方案 |
函数内结构体 | void func() { struct X } | 结构体需在全局或类内定义 |
调用自定义函数时传递未显式声明的参数 | bubbleSort({5, 2, 9, 1, 9, 9, 1, 2, 5.6, 0, 3}); | 应写成bubbleSort(std::vector<double>{5, 2, 9, 1, 9, 9, 1, 2, 5.6, 0, 3}); 或者 std::vector<double> arr{5, 2, 9, 1, 9, 9, 1, 2, 5.6, 0, 3}; bubbleSort(arr); |
- 类的支持不完善,建议优先使用 独立函数 或 类方法
- 避免复杂模板,如自定义模板类可能无法解析
- 不支持 非基础类型的 map 键,以下代码会报错:
请根据上述规则调整代码,如有问题请联系平台支持。