Cxxdroid 中文文档 下载 App

Pastebin 一键分享代码 —— 把代码片段发到 Pastebin 上

什么是 Pastebin

Pastebin.com 是一个免费的文本分享网站——你把一段代码贴上去,它给你一个短链接,发给别人点进去就能看到格式化的代码。

常见使用场景:

Cxxdroid 内置 Pastebin 分享

Cxxdroid 的 Pastebin 功能标星 Premium 版本——免费版可能没有或有限制。Premium 用户:

  1. 在代码编辑器里打开想分享的文件
  2. 菜单里选「Pastebin」或「Share to Pastebin」
  3. 应用自动读取当前文件内容、发请求到 Pastebin API
  4. 成功后返回一个短链接,可以复制或直接分享

手动用 libcurl 实现分享

如果没有 Premium,可以用 Cxxdroid + libcurl 自己实现 Pastebin 分享(前提是你的 libcurl 是 SSL 版本、支持 HTTPS POST)。

Pastebin 的公开 API 大致是:

// 伪代码示意
void shareToPastebin(const std::string &code) {
    std::string postData = "api_dev_key=你的key&"
                         "api_paste_code=" + urlEncode(code) + "&"
                         "api_paste_format=cpp&"
                         "api_paste_private=1";
    // libcurl POST 到 https://pastebin.com/api/api_post.php
}

临时 vs 长期

Pastebin 上的 paste 默认有过期时间:

Cxxdroid 内置分享功能的默认过期时间因版本而异。在 API 请求中可以通过 api_paste_expire_date 参数控制。

隐私注意

Pastebin 上的公开 paste 任何人都能看到。不要粘贴包含以下内容的代码:

如果不确定,设为 api_paste_private=2(私有 paste,只有持有唯一 URL 的人能访问)。

其他 Paste 服务

Pastebin 不是唯一选择:

如果 Cxxdroid 内置的 Pastebin 不满足你的需求,可以用 libcurl 对接这些服务的 API。