# Stats

**URL:** https://heroiclabs.com/docs/hiro/cpp/stats/
**Keywords:** stats, hiro
**Categories:** hiro, cpp, stats

---


# Stats

Read more about the Stats system in Hiro [here](../../concepts/stats/).

## Get all stats

Get all stats.

```cpp
void onStatsGet(const Hiro::StatList& statList)
{
    for (auto it = statList.public_.begin(); it != statList.public_.end(); it++)
    {
        std::cout << "Found public stat: " << it->second.name << '\n';
    }

    for (auto it = statList.private_.begin(); it != statList.private_.end(); it++)
    {
        std::cout << "Found private stat: " << it->second.name << '\n';
    }
}

void onError(const Nakama::NError& error)
{
    std::cout << Nakama::toString(error.code) << ": " << error.message << '\n';
}

hiroClient->statsGet(session, onStatsGet, onError);
```

## Update stats for the player

Update stats.

```cpp
void onStatsUpdate(const Hiro::StatList& statList)
{
    for (auto it = statList.public_.begin(); it != statList.public_.end(); it++)
    {
        std::cout << "Found public stat: " << it->second.name << '\n';
    }

    for (auto it = statList.private_.begin(); it != statList.private_.end(); it++)
    {
        std::cout << "Found private stat: " << it->second.name << '\n';
    }
}

void onError(const Nakama::NError& error)
{
    std::cout << Nakama::toString(error.code) << ": " << error.message << '\n';
}

Hiro::StatUpdateRequest request;

Hiro::StatUpdate statUpdate1;
statUpdate1.name = "public_stat_1";
statUpdate1.value = "100";
statUpdate1.operator_ = Hiro::StatUpdateOperator::STAT_UPDATE_OPERATOR_SET;
request.public_.push_back(statUpdate1);

Hiro::StatUpdate statUpdate2;
statUpdate2.name = "private_stat_1";
statUpdate2.value = "100";
statUpdate2.operator_ = Hiro::StatUpdateOperator::STAT_UPDATE_OPERATOR_SET;
request.private_.push_back(statUpdate2);

hiroClient->statsUpdate(session, request, onStatsUpdate, onError);
```