使用C++比較兩個HTML

高度準確的C++差異檢查器比較HTML文件並發現它們之間的差異

我們強大的C++ SDK可讓您找到HTML文檔之間的差異並將結果保存為方便查看的格式。要驗證我們的產品功能,請使用此C++庫比較HTML文件並查看差異。

看程式碼片段

比較 C++ 中的 HTML

我們的 C++ SDK 旨在為您提供最準確的結果,即使比較本身就是一個複雜的功能。

有時你需要確定 HTML 格式的文檔沒有被改變,如果有,你需要找出有什麼不同。只需使用我們的 C++ diff 工具來比較兩個 HTML 文件並查找整個單詞或單個字符的差異。此外,如果一個單詞中只有一個字符發生了變化,則該單詞將被標記為完全更改。

現在,您不再需要花時間手動比較 HTML 文檔,您可以快速找到哪怕是很小的更改,並以方便的格式將此類差異導出到文檔中。

嘗試比較 HTML 文檔

查看我們使用 C++ SDK 比較 HTML 文件的解決方案如何工作。為此,加載要比較的 HTML 文件並選擇導出文件格式 - 比較後會自動加載。

請注意,在調用比較方法之前,您需要接受比較文檔中的所有修訂,如我們的示例所示:

上傳比較文件
運行代碼
上傳第二個文件進行比較
從列表中選擇目標格式
using namespace aspose::words::cloud;

auto config = 
    std::make_shared<ApiConfiguration>(L"####-####-####-####-####", L"##################");
auto wordsApi = std::make_shared<WordsApi>(config);

std::wstring fileName1 = L"Input1.html";
std::wstring fileName2 = L"Input2.html";
std::wstring fileResult = L"Output.html";

// 將文檔上傳到雲存儲。
auto firstDocumentContent = 
    std::shared_ptr<std::istream>(
	new std::ifstream(std::filesystem::path(fileName1), std::istream::binary));
std::shared_ptr<requests::UploadFileRequest> uploadFirstFileRequest(
    new requests::UploadFileRequest(
        firstDocumentContent, std::make_shared<std::wstring>(fileName1)
    )
);
wordsApi->uploadFile(uploadFirstFileRequest);

auto secondDocumentContent = 
    std::shared_ptr<std::istream>(
	new std::ifstream(std::filesystem::path(fileName2), std::istream::binary));
std::shared_ptr<requests::UploadFileRequest> uploadSecondFileRequest(
    new requests::UploadFileRequest(
        secondDocumentContent, std::make_shared<std::wstring>(fileName2)
    )
);
wordsApi->uploadFile(uploadSecondFileRequest);

// 比較雲中的文檔。
auto compareDataOptions = std::make_shared<aspose::words::cloud::models::CompareData>();
compareDataOptions->setAuthor(std::make_shared<std::wstring>(L"author"));
compareDataOptions->setComparingWithDocument(std::make_shared<std::wstring>(fileName2));
std::shared_ptr<requests::CompareDocumentRequest> compareDocumentRequest(
    new requests::CompareDocumentRequest(
        std::make_shared<std::wstring>(fileName1), 
		compareDataOptions, std::make_shared<std::wstring>(fileResult)
    )
);
wordsApi->compareDocument(compareDocumentRequest);

// 從雲存儲下載結果文檔。
std::shared_ptr<requests::DownloadFileRequest> downloadFileRequest(
    new requests::DownloadFileRequest(
        std::make_shared<std::wstring>(fileResult)
    )
);
auto downloadFileResult = wordsApi->downloadFile(downloadFileRequest);
{
    char buffer[1024];
    std::ofstream fileWriter(fileResult, std::ofstream::binary);
    const auto& fileData = *downloadFileResult->begin();
    while(fileData.second->read(buffer, sizeof(buffer))) {
        fileWriter.write(buffer, sizeof(buffer));
    }
    fileWriter.write(buffer, fileData.second->gcount());
    fileWriter.close();
}
運行代碼
  
將代碼C++複製到剪貼板

如何比較兩個文本文件

  1. Aspose.Words Cloud for C++
  2. 將庫引用(導入庫)添加到您的C++項目
  3. 加載兩個HTML文檔以進行比較
  4. 調用compareDocument()方法來比較HTML文檔
  5. 從雲存儲下載結果文檔

C++庫使用比較

從 GitHub 克隆 Aspose.Words Cloud SDK for C++ 源代碼。您可以在 "How to use the SDK" 部分找到有關構建和配置 SDK 的詳細信息。

要快速獲取必要的安全憑證並訪問我們的 REST API,請按照文檔中的這些 Instructions 進行操作。

系統要求

請參閱 Repository Documentation 以查看詳細信息。

其他支持的文件格式

您可以對其他文件格式執行比較操作:

5%

訂閱 Aspose 產品更新

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

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