Compare two Word using C++

Highly accurate C++ diff checker to compare Word files and find differences between them

Our powerful C++ SDK allows you to find the difference between Word documents and save the results to a convenient format for viewing. To verify our product capabilities, compare Word files using this C++ library and see the differences.

View code snippet

Compare Word in C++

Our C++ SDK is designed to give you the most accurate result, even though comparison is a complex function itself.

Sometimes you need to be sure that the document in the Word format has not been changed, and if it has, you need to find out what the difference is. Just use our C++ diff tool to compare two Word files and find differences in whole words or single characters. Moreover, if only one character in a word has changed, this word will be marked as changed entirely.

Now you no longer need to spend time manually comparing Word documents, and you can quickly find even small changes and export such diffs to a document in a convenient format.

Try to compare Word documents

Check out how our solution to compare Word files using C++ SDK works. To achieve this, load the Word files you want to compare and select the export file format – it will be automatically loaded after comparing.

Note that you need to accept all revisions in compared documents before calling the comparison method, as shown in our example:

Upload the compared file
Run code
Upload the second file to compare
Select the target format from the list
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.docx";
std::wstring fileName2 = L"Input2.docx";
std::wstring fileResult = L"Output.docx";

//  Upload documents to cloud storage.
auto firstDocumentContent = 
	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)

auto secondDocumentContent = 
	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)

//  Compare documents in cloud.
auto compareDataOptions = std::make_shared<aspose::words::cloud::models::CompareData>();
std::shared_ptr<requests::CompareDocumentRequest> compareDocumentRequest(
    new requests::CompareDocumentRequest(
		compareDataOptions, std::make_shared<std::wstring>(fileResult)

//  Download result document from cloud storage.
std::shared_ptr<requests::DownloadFileRequest> downloadFileRequest(
    new requests::DownloadFileRequest(
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());
Run code
Copy C++ code to the clipboard

How to Compare two text files

  1. Install Aspose.Words Cloud for C++
  2. Add a library reference (import the library) to your C++ project
  3. Load two Word documents to compare
  4. Call the compareDocument() method to compare Word docs
  5. Download the result document from the cloud storage

C++ library to use compare

Clone Aspose.Words Cloud SDK for C++ source code from GitHub. You can find detailed information on building and configuring the SDK in the "How to use the SDK" section.

To quickly get the necessary security credentials and access our REST API, please follow these Instructions in the documentation.

System Requirements

Refer to the Repository Documentation to see the details.

Other supported file formats

You can perform compare operation for other file formats:


Subscribe to Aspose Product Updates

Get monthly newsletters and offers directly delivered to your mailbox.

© Aspose Pty Ltd 2001-2024. All Rights Reserved.