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\u003eThis webpage provides documentation for the Cloud Spanner C++ Client library, which enables C++ applications to interact with Cloud Spanner.\u003c/p\u003e\n"],["\u003cp\u003eThe latest version of the client library is 2.37.0-rc, and there are many previous versions available for browsing, starting from version 2.11.0 up until the latest version.\u003c/p\u003e\n"],["\u003cp\u003eThe "Hello World" quickstart code example demonstrates how to use the library to execute a simple query, and it provides guidance on incorporating the library into projects.\u003c/p\u003e\n"],["\u003cp\u003eThe library offers functionalities like \u003ccode\u003eClient::ExecuteQuery()\u003c/code\u003e, \u003ccode\u003eClient::Commit()\u003c/code\u003e, and \u003ccode\u003eClient::Read()\u003c/code\u003e for executing queries, managing transactions, and reading data from tables.\u003c/p\u003e\n"],["\u003cp\u003eThe library offers useful information, such as how to handle runtime errors, the use of environment variables, and how to override default settings, among other resources.\u003c/p\u003e\n"]]],[],null,["Version 2.12.0keyboard_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.12.0/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.12.0/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.12.0/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.12.0/spanner-error-handling) to learn how the library reports run-time errors.\n- [Environment Variables](/cpp/docs/reference/spanner/2.12.0/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 the default endpoint](/cpp/docs/reference/spanner/2.12.0/spanner-endpoint-example)\n- [Override the authentication configuration](/cpp/docs/reference/spanner/2.12.0/spanner-auth-example)\n- [Retry, Backoff, and Idempotency Policies.](/cpp/docs/reference/spanner/2.12.0/spanner-retry-example)\n- [Mocking the Cloud Spanner C++ Client with Google Mock](/cpp/docs/reference/spanner/2.12.0/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."]]