在 C++ 中檢查 Word、PDF、Web 文件的語法

使用 AI 進行語法檢查的 C++ 解決方案

與 OpenAI、Claude 與 Gemini 等主流大型語言模型無縫整合,為 C++ 應用程式提供廣泛的 AI 驅動文件處理功能。

查看代碼片段

C++ 文件的 AI 文法檢查工具

使用 Aspose.Words for C++ 搭配 OpenAI、Google 與 Claude AI 模型,偵測並標示文件中的文法錯誤。CheckGrammar 方法會分析 DOC、DOCX、RTF、PDF、HTML、Markdown、ODT、TXT 與 EPUB 檔案,並標記文法問題 — 協助您無需手動校對即可產出完美且專業的內容。

為什麼開發人員選擇 Aspose.Words 進行文法檢查

  • 只需一次 API 呼叫即可檢查整份文件的文法
  • 支援 OpenAI (GPT-4o)、Google (Gemini) 與 Claude 模型系列
  • 在輸出的文件中醒目提示錯誤,方便進行檢閱
  • 支援 DOC、DOCX、RTF、PDF、ODT、HTML、Markdown、TXT、EPUB 及更多格式

驗證需要您所選擇之 AI 提供者的 API 金鑰。如需支援模型的完整清單,請參閱 API 參考資料

立即開始檢查 C++ 中的文法 — 試用上方的即時示範。

使用 C++ 的語法檢查範例程式碼
從列表中選擇目標格式
運行代碼
dotnet add package Aspose.Words.Cpp
複製
auto doc = System::MakeObject<Aspose::Words::Document>(u"Document.docx");
auto apiKey = System::Environment::GetEnvironmentVariable(u"API_KEY");

// 使用 OpenAI 的生成式語言模型。
SharedPtr<AiModel> model = System::ExplicitCast<OpenAiModel>(SharedPtr<AiModel>()->Create(AiModelType::Gpt4OMini)->WithApiKey(apiKey));

auto grammarOptions = MakeObject<CheckGrammarOptions>();
grammarOptions->set_ImproveStylistics(true);

auto proofedDoc = model->CheckGrammar(doc, grammarOptions);
proofedDoc->Save(u"Output.docx");
auto doc = System::MakeObject<Aspose::Words::Document>(u"Document.docx");
// Pass an empty string if the self-hosted model does not require an API key.
auto model = System::MakeObject<CustomAiModel>(u"my-model-24b", u"https://your-server.com/v1");
model->WithApiKey(u"");

auto grammarOptions = System::MakeObject<Aspose::Words::AI::CheckGrammarOptions>();
grammarOptions->set_ImproveStylistics(true);

auto proofedDoc = model->CheckGrammar(doc, grammarOptions);
proofedDoc->Save(u"Output.docx");

class CustomAiModel : public Aspose::Words::AI::OpenAiModel
{
private:
    System::String mUrl;
public:
    CustomAiModel(System::String name, System::String url) : OpenAiModel(name) { mUrl = url; }
    System::String get_Url() override { return mUrl; }
};
運行代碼

如何使用 C++ 檢查文件的語法

  1. 安裝 Aspose.Words for C++。
  2. 在您的 C++ 專案中加入函式庫參考(匯入函式庫)。
  3. 在 C++ 中開啟來源檔案。
  4. 呼叫 CheckGrammar 方法,並傳入您的文件。
  5. 完成後,文件中的語法問題將被標示,您可將結果另存為所需格式的新檔案。

C++ 函式庫,用於語法檢查

有三個選項可以將 Aspose.Words for C++ 安裝到您的開發人員環境中。請選擇符合您需求的一種,並按照分步說明進行操作:

系統要求

您可以使用這個 C++ 庫在 Microsoft Windows 、Linux 和 macOS 操作系統上開發軟件:

  • Linux 需要 GCC >= 6.3.0 和 Clang >= 3.9.1
  • Xcode >= 12.5.1 ,macOS 需要 Clang 和 libc++

如果您為 Linux 或 macOS 開發軟件,請查看產品文檔中 fontconfig 和 mesa-glu 開源包)的信息。

5%

訂閱 Aspose 產品更新

獲取直接發送到您的郵箱的每月通訊和優惠。

© Aspose Pty Ltd 2001-2026. 版權所有。