The Google Cloud Storage (GCS) C++ Client library offers types and functions access GCS from C++ applications. It offers full access to the GCS API, including operations to list, read, write, and deleteGCS objectsandbuckets. The library also provides functions to modify the IAM permissions on buckets, read and modify the metadata associated with objects and buckets, configure encryption keys, configure notifications via Cloud Pub/Sub, and change the access control list of object or buckets.
Quickstart
The following "Hello World" program should give you a taste of this library. This program is also used to illustrate how to incorporate the library into your project.
#include "google/cloud/storage/client.h"
#include <iostream>
int main(int argc, char* argv[]) {
if (argc != 2) {
std::cerr << "Missing bucket name.\n";
std::cerr << "Usage: quickstart <bucket-name>\n";
return 1;
}
std::string const bucket_name = argv[1];
// Create aliases to make the code easier to read.
namespace gcs = ::google::cloud::storage;
// Create a client to communicate with Google Cloud Storage. This client
// uses the default configuration for authentication and project id.
auto client = gcs::Client();
auto writer = client.WriteObject(bucket_name, "quickstart.txt");
writer << "Hello World!";
writer.Close();
if (!writer.metadata()) {
std::cerr << "Error creating object: " << writer.metadata().status()
<< "\n";
return 1;
}
std::cout << "Successfully created object: " << *writer.metadata() << "\n";
auto reader = client.ReadObject(bucket_name, "quickstart.txt");
if (!reader) {
std::cerr << "Error reading object: " << reader.status() << "\n";
return 1;
}
std::string contents{std::istreambuf_iterator<char>{reader}, {}};
std::cout << contents << "\n";
return 0;
}
Error Handlingto learn how the library reports run-time errors.
Environment Variablesfor environment variables affecting the library. Some of these environment variables enable logging to the console. This can be an effective approach to diagnose runtime problems.
TheSetting up your development environmentguide describes how to set up a C++ development environment in various platforms, including the Google Cloud C++ client libraries.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[[["\u003cp\u003eThe Google Cloud Storage C++ Client library provides comprehensive access to the GCS API for C++ applications, allowing operations like listing, reading, writing, and deleting objects and buckets.\u003c/p\u003e\n"],["\u003cp\u003eThis library allows modification of IAM permissions, metadata management, encryption key configuration, Cloud Pub/Sub notifications, and access control list changes for GCS buckets and objects.\u003c/p\u003e\n"],["\u003cp\u003eThe "Hello World" example demonstrates how to utilize the library to create, write to, and read from GCS objects, illustrating the ease of incorporating it into C++ projects.\u003c/p\u003e\n"],["\u003cp\u003eMultiple functions are provided to enable various object operations, including \u003ccode\u003eReadObject()\u003c/code\u003e for data retrieval, \u003ccode\u003eWriteObject()\u003c/code\u003e for writing data, and \u003ccode\u003eInsertObject()\u003c/code\u003e for handling small objects.\u003c/p\u003e\n"],["\u003cp\u003eThe library offers features such as error handling, customizable environment variables, endpoint and authentication overrides, retry policy adjustments, and guidance on mock client usage for testing.\u003c/p\u003e\n"]]],[],null,["Version 2.12.0keyboard_arrow_down\n\n- [2.42.0-rc (latest)](/cpp/docs/reference/storage/latest)\n- [2.41.0](/cpp/docs/reference/storage/2.41.0)\n- [2.40.0](/cpp/docs/reference/storage/2.40.0)\n- [2.39.0](/cpp/docs/reference/storage/2.39.0)\n- [2.38.0](/cpp/docs/reference/storage/2.38.0)\n- [2.37.0](/cpp/docs/reference/storage/2.37.0)\n- [2.36.0](/cpp/docs/reference/storage/2.36.0)\n- [2.35.0](/cpp/docs/reference/storage/2.35.0)\n- [2.34.0](/cpp/docs/reference/storage/2.34.0)\n- [2.33.0](/cpp/docs/reference/storage/2.33.0)\n- [2.32.0](/cpp/docs/reference/storage/2.32.0)\n- [2.31.0](/cpp/docs/reference/storage/2.31.0)\n- [2.30.0](/cpp/docs/reference/storage/2.30.0)\n- [2.29.0](/cpp/docs/reference/storage/2.29.0)\n- [2.28.0](/cpp/docs/reference/storage/2.28.0)\n- [2.27.0](/cpp/docs/reference/storage/2.27.0)\n- [2.26.0](/cpp/docs/reference/storage/2.26.0)\n- [2.25.1](/cpp/docs/reference/storage/2.25.1)\n- [2.24.0](/cpp/docs/reference/storage/2.24.0)\n- [2.23.0](/cpp/docs/reference/storage/2.23.0)\n- [2.22.1](/cpp/docs/reference/storage/2.22.1)\n- [2.21.0](/cpp/docs/reference/storage/2.21.0)\n- [2.20.0](/cpp/docs/reference/storage/2.20.0)\n- [2.19.0](/cpp/docs/reference/storage/2.19.0)\n- [2.18.0](/cpp/docs/reference/storage/2.18.0)\n- [2.17.0](/cpp/docs/reference/storage/2.17.0)\n- [2.16.0](/cpp/docs/reference/storage/2.16.0)\n- [2.15.1](/cpp/docs/reference/storage/2.15.1)\n- [2.14.0](/cpp/docs/reference/storage/2.14.0)\n- [2.13.0](/cpp/docs/reference/storage/2.13.0)\n- [2.12.0](/cpp/docs/reference/storage/2.12.0)\n- [2.11.0](/cpp/docs/reference/storage/2.11.0) \n\nGoogle Cloud Storage C++ Client Library\n=======================================\n\nThe Google Cloud Storage (GCS) C++ Client library offers types and functions access GCS from C++ applications. It offers full access to the GCS API, including operations to list, read, write, and delete [GCS objects](https://cloud.google.com/storage/docs/key-terms#objects) and [buckets](https://cloud.google.com/storage/docs/key-terms#buckets). The library also provides functions to modify the IAM permissions on buckets, read and modify the metadata associated with objects and buckets, configure encryption keys, configure notifications via Cloud Pub/Sub, and change the access control list of object or buckets.\n\n### Quickstart\n\nThe following \"Hello World\" program should give you a taste of this library. This program is also used to illustrate how to incorporate the library into your project. \n\n #include \"google/cloud/storage/client.h\"\n #include \u003ciostream\u003e\n\n int main(int argc, char* argv[]) {\n if (argc != 2) {\n std::cerr \u003c\u003c \"Missing bucket name.\\n\";\n std::cerr \u003c\u003c \"Usage: quickstart \u003cbucket-name\u003e\\n\";\n return 1;\n }\n std::string const bucket_name = argv[1];\n\n // Create aliases to make the code easier to read.\n namespace gcs = ::google::cloud::storage;\n\n // Create a client to communicate with Google Cloud Storage. This client\n // uses the default configuration for authentication and project id.\n auto client = gcs::Client();\n\n auto writer = client.WriteObject(bucket_name, \"quickstart.txt\");\n writer \u003c\u003c \"Hello World!\";\n writer.Close();\n if (!writer.metadata()) {\n std::cerr \u003c\u003c \"Error creating object: \" \u003c\u003c writer.metadata().status()\n \u003c\u003c \"\\n\";\n return 1;\n }\n std::cout \u003c\u003c \"Successfully created object: \" \u003c\u003c *writer.metadata() \u003c\u003c \"\\n\";\n\n auto reader = client.ReadObject(bucket_name, \"quickstart.txt\");\n if (!reader) {\n std::cerr \u003c\u003c \"Error reading object: \" \u003c\u003c reader.status() \u003c\u003c \"\\n\";\n return 1;\n }\n\n std::string contents{std::istreambuf_iterator\u003cchar\u003e{reader}, {}};\n std::cout \u003c\u003c contents \u003c\u003c \"\\n\";\n\n return 0;\n }\n\n### More Information\n\n- [ReadObject()](/cpp/docs/reference/storage/2.12.0/classgoogle_1_1cloud_1_1storage_1_1Client#classgoogle_1_1cloud_1_1storage_1_1Client_1a8b0575846b68475f6b1f7ef950b49323) - the function to read object data.\n- [WriteObject()](/cpp/docs/reference/storage/2.12.0/classgoogle_1_1cloud_1_1storage_1_1Client#classgoogle_1_1cloud_1_1storage_1_1Client_1a8918b5f338d91607b06d5107965ed35e) - the function to write objects.\n- [InsertObject()](/cpp/docs/reference/storage/2.12.0/classgoogle_1_1cloud_1_1storage_1_1Client#classgoogle_1_1cloud_1_1storage_1_1Client_1ace17975b9eeae9df0da67712a430a349) - the function to write small objects.\n- [Error Handling](/cpp/docs/reference/storage/2.12.0/storage-error) to learn how the library reports run-time errors.\n- [Environment Variables](/cpp/docs/reference/storage/2.12.0/storage-env) for environment variables affecting the library. Some of these environment variables enable logging to the console. This can be an effective approach to diagnose runtime problems.\n- [Override the Default Endpoint](/cpp/docs/reference/storage/2.12.0/storage-endpoint-example)\n- [Override the authentication configuration](/cpp/docs/reference/storage/2.12.0/storage-auth-example)\n- [Override the default retry policies](/cpp/docs/reference/storage/2.12.0/storage-retry-examples)\n- [Writing Tests with a Mock Client](/cpp/docs/reference/storage/2.12.0/storage-mocking) shows how to write tests mocking the [Client](/cpp/docs/reference/storage/2.12.0/classgoogle_1_1cloud_1_1storage_1_1Client) class\n- The [Setting up your development environment](https://cloud.google.com/cpp/docs/setup) guide describes how to set up a C++ development environment in various platforms, including the Google Cloud C++ client libraries."]]