The Cloud Spanner C++ Client library offers types and functions to use Cloud Spanner from C++ applications.
Quickstart
The following "Hello World" program should give you a sense of how to use this library. This program is also used to illustrate how to incorporate the library into your project.
Error Handling to learn how the library reports run-time errors.
Environment Variables 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.
The Setting up your development environment guide 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"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-22 UTC."],[[["\u003cp\u003eThe Cloud Spanner C++ Client library provides tools for C++ applications to interact with Cloud Spanner, offering functionalities like executing SQL queries and managing transactions.\u003c/p\u003e\n"],["\u003cp\u003eVersion 2.37.0-rc is the latest release candidate, while the most recent stable release is 2.36.0, and a list of previous versions is available for reference.\u003c/p\u003e\n"],["\u003cp\u003eThe library allows the user to execute SQL queries, perform read-write transactions, and directly read rows in a table via \u003ccode\u003eClient::ExecuteQuery()\u003c/code\u003e, \u003ccode\u003eClient::Commit()\u003c/code\u003e, and \u003ccode\u003eClient::Read()\u003c/code\u003e respectively.\u003c/p\u003e\n"],["\u003cp\u003eThe library provides comprehensive error handling mechanisms, environment variable controls, and ways to customize retry policies, endpoint settings, and authentication configurations.\u003c/p\u003e\n"],["\u003cp\u003eA quickstart "Hello World" program is provided as an example of how to use the library, along with a link to the setup guide for development environments.\u003c/p\u003e\n"]]],[],null,["Version 2.15.1keyboard_arrow_down\n\n- [2.42.0-rc (latest)](/cpp/docs/reference/spanner/latest)\n- [2.41.0](/cpp/docs/reference/spanner/2.41.0)\n- [2.40.0](/cpp/docs/reference/spanner/2.40.0)\n- [2.39.0](/cpp/docs/reference/spanner/2.39.0)\n- [2.38.0](/cpp/docs/reference/spanner/2.38.0)\n- [2.37.0](/cpp/docs/reference/spanner/2.37.0)\n- [2.36.0](/cpp/docs/reference/spanner/2.36.0)\n- [2.35.0](/cpp/docs/reference/spanner/2.35.0)\n- [2.34.0](/cpp/docs/reference/spanner/2.34.0)\n- [2.33.0](/cpp/docs/reference/spanner/2.33.0)\n- [2.32.0](/cpp/docs/reference/spanner/2.32.0)\n- [2.31.0](/cpp/docs/reference/spanner/2.31.0)\n- [2.30.0](/cpp/docs/reference/spanner/2.30.0)\n- [2.29.0](/cpp/docs/reference/spanner/2.29.0)\n- [2.28.0](/cpp/docs/reference/spanner/2.28.0)\n- [2.27.0](/cpp/docs/reference/spanner/2.27.0)\n- [2.26.0](/cpp/docs/reference/spanner/2.26.0)\n- [2.25.1](/cpp/docs/reference/spanner/2.25.1)\n- [2.24.0](/cpp/docs/reference/spanner/2.24.0)\n- [2.23.0](/cpp/docs/reference/spanner/2.23.0)\n- [2.22.1](/cpp/docs/reference/spanner/2.22.1)\n- [2.21.0](/cpp/docs/reference/spanner/2.21.0)\n- [2.20.0](/cpp/docs/reference/spanner/2.20.0)\n- [2.19.0](/cpp/docs/reference/spanner/2.19.0)\n- [2.18.0](/cpp/docs/reference/spanner/2.18.0)\n- [2.17.0](/cpp/docs/reference/spanner/2.17.0)\n- [2.16.0](/cpp/docs/reference/spanner/2.16.0)\n- [2.15.1](/cpp/docs/reference/spanner/2.15.1)\n- [2.14.0](/cpp/docs/reference/spanner/2.14.0)\n- [2.13.0](/cpp/docs/reference/spanner/2.13.0)\n- [2.12.0](/cpp/docs/reference/spanner/2.12.0)\n- [2.11.0](/cpp/docs/reference/spanner/2.11.0) \n\nCloud Spanner C++ Client Library\n================================\n\nThe Cloud Spanner C++ Client library offers types and functions to use Cloud Spanner from C++ applications.\n\n### Quickstart\n\nThe following \"Hello World\" program should give you a sense of how to use this library. This program is also used to illustrate how to incorporate the library into your project. \n\n #include \"google/cloud/spanner/client.h\"\n #include \u003ciostream\u003e\n\n int main(int argc, char* argv[]) {\n if (argc != 4) {\n std::cerr \u003c\u003c \"Usage: \" \u003c\u003c argv[0]\n \u003c\u003c \" project-id instance-id database-id\\n\";\n return 1;\n }\n\n namespace spanner = ::google::cloud::spanner;\n spanner::Client client(\n spanner::MakeConnection(spanner::Database(argv[1], argv[2], argv[3])));\n\n auto rows =\n client.ExecuteQuery(spanner::SqlStatement(\"SELECT 'Hello World'\"));\n\n for (auto const& row : spanner::StreamOf\u003cstd::tuple\u003cstd::string\u003e\u003e(rows)) {\n if (!row) {\n std::cerr \u003c\u003c row.status() \u003c\u003c \"\\n\";\n return 1;\n }\n std::cout \u003c\u003c std::get\u003c0\u003e(*row) \u003c\u003c \"\\n\";\n }\n\n return 0;\n }\n\n### More Information\n\n- Read more about [Cloud Spanner](https://cloud.google.com/spanner/docs/)\n- [`Client::ExecuteQuery()`](/cpp/docs/reference/spanner/2.15.1/classgoogle_1_1cloud_1_1spanner_1_1Client#classgoogle_1_1cloud_1_1spanner_1_1Client_1a8e2afee42f535c0436d9161c54b84179) to execute SQL queries in Cloud Spanner.\n- [`Client::Commit()`](/cpp/docs/reference/spanner/2.15.1/classgoogle_1_1cloud_1_1spanner_1_1Client#classgoogle_1_1cloud_1_1spanner_1_1Client_1ae83521aef8045ac04b0a5dc85b08a2d9) to execute read-write transactions in Cloud Spanner.\n- [`Client::Read()`](/cpp/docs/reference/spanner/2.15.1/classgoogle_1_1cloud_1_1spanner_1_1Client#classgoogle_1_1cloud_1_1spanner_1_1Client_1a167955c44cd3ccb46ffe07cad6e7e52b) to read the rows in a table.\n- [Error Handling](/cpp/docs/reference/spanner/2.15.1/spanner-error-handling) to learn how the library reports run-time errors.\n- [Environment Variables](/cpp/docs/reference/spanner/2.15.1/spanner-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 Retry, Backoff, and Re-Run Policies](/cpp/docs/reference/spanner/2.15.1/spanner-retry-policies) to learn how to override the default retry policies used by the library.\n- [Override the default endpoint](/cpp/docs/reference/spanner/2.15.1/spanner-endpoint-example)\n- [Override the authentication configuration](/cpp/docs/reference/spanner/2.15.1/spanner-auth-example)\n- [Mocking the Cloud Spanner C++ Client with Google Mock](/cpp/docs/reference/spanner/2.15.1/spanner-mocking)\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."]]