This example is a simple "hello world" application, written in C++, that illustrates how to do the following:

  • Set up authentication
  • Connect to a Bigtable instance.
  • Create a new table.
  • Write data to the table.
  • Read the data back.
  • Delete the table.

Set up authentication

To use the C++ samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.

  1. Install the Google Cloud CLI.

  2. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  3. If you're using a local shell, then create local authentication credentials for your user account:

    gcloud auth application-default login

    You don't need to do this if you're using Cloud Shell.

    If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.

For more information, see Set up authentication for a local development environment.

Running the sample

This example uses the Cloud Bigtable package of the Google Cloud client library for C++ to communicate with Bigtable.

To run this sample program, follow the instructions on GitHub.

Using the Google Cloud client library with Bigtable

The sample application connects to Bigtable and demonstrates some simple operations.

Installing and importing the client library

Download or clone the Bigtable C++ client library from GitHub, then compile it. Follow the compiler instructions on the top-level README.

Include the required headers.

Connecting to Bigtable

Use MakeBigtableTableAdminConnection() to construct a BigtableTableAdminClient, which you will use to create a table.

Creating a table

Define a schema for the table that has one column family. Set a garbage collection rule for the column family to keep a maximum of one version of each value. Use that schema to instantiate a table object using BigtableTableAdminClient::CreateTable(). Then create a data client that you can use to get data in and out of your table.

Writing rows to a table

Loop through a list of greeting strings to create some new rows for the table. In each iteration, use SingleRowMutation to define a row and assign it a row key and value. Then call Table::Apply() to apply the mutation to the row.

Creating a filter

Before you read the data that you wrote, create a filter, using Filter::ColumnRangeClosed(), to limit the data that Bigtable returns. This filter tells Bigtable to return only the most recent version of each value, even if the table contains older cells that have expired but have not yet been removed by garbage collection.

Reading a row by its key

Call the Table::ReadRow() function, passing in the row key and the filter, to get one version of each value in that row.

Scanning all table rows

Use Table::ReadRows() to read a range of rows from the table.

Deleting a table

Delete the table with BigtableTableAdminClient::DeleteTable().

Putting it all together

Here is the full example without comments.

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-04-01 UTC.