C++ 代码支持文档

本文档说明当前平台对 C++ 语言的支持范围和限制。
请在使用时注意以下规则,避免使用不兼容的语法特性。

常见问题

常见问题

支持的功能

1. 基础数据类型

支持以下基础类型的声明和使用:
char, string, bool, int, float, double

示例:

2. 标准容器

支持以下容器及其嵌套形式:

容器类型示例
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_mapKey 必须为基础类型char/string/bool/int/float/double
  • 容器嵌套深度最多支持到 2层(如 vector<vector<int>>

3. 内置数据结构

可直接使用以下预定义结构:

4. 语言特性

  • 代码中必须包含以 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()不支持类静态方法
匿名函数(无 &[](\){ ... }必须写成 [&](\){ ... }
stringstreamss << "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);

其他限制

  1. 类的支持不完善,建议优先使用 独立函数类方法
  2. 避免复杂模板,如自定义模板类可能无法解析
  3. 不支持 非基础类型的 map 键,以下代码会报错:

代码示例


请根据上述规则调整代码,如有问题请联系平台支持。