本文主要介绍判断文件是否存在。

以下代码用于判断文件是否存在:
#include <alibabacloud/oss/OssClient.h>
using namespace AlibabaCloud::OSS;

int main(void)
{
    /* 初始化OSS账号信息 */
    std::string AccessKeyId = "yourAccessKeyId";
    std::string AccessKeySecret = "yourAccessKeySecret";
    std::string Endpoint = "yourEndpoint";
    std::string BucketName = "yourBucketName";
    std::string ObjectName = "yourObjectName";
 
    /* 初始化网络等资源 */
    InitializeSdk();

    ClientConfiguration conf;
    OssClient client(Endpoint, AccessKeyId, AccessKeySecret, conf);
  
    /* 判断文件是否存在 */
    auto outcome = client.DoesObjectExist(BucketName, ObjectName);

    if (outcome) {
      std::cout << "The Object exists!" << std::endl;                       
    }                              
    else {                         
      std::cout << "The Object does not exist!" << std::endl;
    }
    
    /* 释放网络等资源 */
    ShutdownSdk();
    return 0;
}