A bucket is a container for objects stored in OSS. Every object is contained in a bucket. This topic describes how to list buckets.

The following code provides an example on how to list all buckets:

#include <alibabacloud/oss/OssClient.h>
using namespace AlibabaCloud::OSS;

int main(void)
    /*Initialize the OSS account information.*/
    std::string AccessKeyId = "yourAccessKeyId";
    std::string AccessKeySecret = "yourAccessKeySecret";
    std::string Endpoint = "yourEndpoint";

    /*Initialize network resources.*/

    ClientConfiguration conf;
    OssClient client(Endpoint, AccessKeyId, AccessKeySecret, conf);

    /*List the buckets.*/
    ListBucketsRequest request;
    auto outcome = client.ListBuckets(request);

    if (outcome.isSuccess()) {
        /*Obtain the bucket information.*/
        std::cout <<" success, and bucket count is" << outcome.result().Buckets().size() << std::endl;
        std::cout << "Bucket name is" << std::endl;
        for (auto result : outcome.result().
            std::cout << result.Name() << std::endl;
    else {
        /*Handle exceptions.*/
        std::cout << "ListBuckets fail" <<
        ",code:" << outcome.error().Code() <<
        ",message:" << outcome.error().Message() <<
        ",requestId:" << outcome.error().RequestId() << std::endl;
        return -1;

    /*Release network resources.*/
    return 0;

For more information about how to list buckets, see GetBucket (ListObject).