Get Started with Firebase Realtime Database for C++

The Firebase Realtime Database stores and synchronizes data using a NoSQL clouddatabase. Data is synchronized across all clients in realtime, and remainsavailable when your app goes offline.

Before You Begin

Before you can useFirebase Realtime Database,you need to:

  • Register your C++ project and configure it to use Firebase.

    If your C++ project already uses Firebase, then it's already registered andconfigured for Firebase.

  • Add theFirebaseC++ SDK to your C++ project.

Find detailed instructions for these initial setup tasks inAdd Firebase to your C++ project.

Note that adding Firebase to your C++ project involves tasks both in theFirebase console and in your open C++ project (for example, you downloadFirebase config files from the console, then move them into your C++ project).

Create a Database

  1. Navigate to theRealtime Database section of theFirebase console.You'll be prompted to select an existing Firebase project.Follow the database creation workflow.

  2. Select a starting mode for yourFirebase Security Rules:

    Test mode

    Good for getting started with the mobile and web client libraries,but allows anyone to read and overwrite your data. After testing,makesure to review theUnderstand Firebase Realtime Database Rulessection.

    Note: If you create a database in Test mode and make no changes to thedefault world-readable and world-writeableRules within a trialperiod, you will be alerted by email, then your database rules willdeny all requests. Note the expiration date during theFirebase consolesetup flow.

    To get started with the web, Apple, or Android SDK, select testmode.

    Locked mode

    Denies all reads and writes from mobile and web clients.Your authenticated application servers can still access your database.

  3. Choose a location for the database.

    Depending on thelocation of the database, theURL for the new database will be in one of the following forms:

    • DATABASE_NAME.firebaseio.com (fordatabases inus-central1)

    • DATABASE_NAME.REGION.firebasedatabase.app(for databases in all other locations)

  4. ClickDone.

When you enableRealtime Database, it also enables the API in theCloud API Manager.

Create and Initialize firebase::App

Before you can access theRealtime Database, you'll need to create and initialize thefirebase::App.

You only need to initialize firebase::App once, no matterhow many Firebase C++ features you use.

Include the header file forfirebase::App:

#include"firebase/app.h"

Android

Create thefirebase::App, passing the JNI environment and ajobjectreference to the Java Activity as arguments:

app=::firebase::App::Create(::firebase::AppOptions("APPLICATION NAME"),jni_env,activity);

iOS+

Create thefirebase::App:

app=::firebase::App::Create(::firebase::AppOptions("APPLICATION NAME"));

Access the firebase::database::Database Class

Thefirebase::database::Databaseis the entry point for theFirebase Realtime Database C++ SDK.

::firebase::database::Database*database=::firebase::database::Database::GetInstance(app);

If you have chosen to use public access for your rules, you can proceed to thesections on saving and retrieving data.

Setting up Restricted Access

If you do not want to use public access you can addFirebase Authentication to yourapp to control access to the database.

Next Steps

Known Issues

  • On desktop platforms (Windows, Mac, Linux), theFirebaseC++ SDK usesREST to access your database. Because of this, you mustdeclare the indexes you usewith Query::OrderByChild() on desktop or your listeners will fail.
  • The desktop workflow version ofRealtime Database does not support offline orpersistence.

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

Last updated 2025-12-17 UTC.