获取SDK

git clone https://github.com/aliyun/aliyun-openapi-cpp-sdk.git

使用示例

#include <iostream>
#include <alibabacloud/core/AlibabaCloud.h>
#include <alibabacloud/nlp-automl/Nlp_automlClient.h>

using namespace AlibabaCloud;
using namespace AlibabaCloud::Nlp_automl;

int main(int argc, char** argv) {
  // 初始化 SDK
  AlibabaCloud::InitializeSdk();

  // 配置 nlp_automl 实例
  ClientConfiguration configuration("<your-region-id>");
  Nlp_automlClient client("<your-access-key-id>", "<your-access-key-secret>", configuration);

  // 创建API请求并设置参数
  Model::GetPredictResultRequest request;
  request.setModelId(1818);
  request.setContent("中华人民共和国解放军");

  auto outcome = client.getPredictResult(request);
  if (!outcome.isSuccess()) {
    // 异常处理
    std::cout << outcome.error().errorCode() << std::endl;
    AlibabaCloud::ShutdownSdk();
    return -1;
  }

  std::cout << "totalCount: " << outcome.result().getTotalCount() << std::endl;

  // 关闭 SDK
  AlibabaCloud::ShutdownSdk();
  return 0;
}