---
source_url: https://www.pubnub.com/docs/sdks/windows-cpp/api-reference/channel-groups
title: Channel Groups API for Windows C++ SDK
updated_at: 2026-06-17T11:41:27.108Z
sdk_name: PubNub Windows C++ SDK
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Channel Groups API for Windows C++ SDK

PubNub Windows C++ SDK

[Channel groups](https://www.pubnub.com/docs/general/channels/subscribe#channel-groups) allow PubNub developers to bundle thousands of [channels](https://www.pubnub.com/docs/general/channels/overview) into a group that can be identified by a name. These channel groups can then be subscribed to, receiving data from the many back-end channels the channel group contains.

:::note Channel group operations
You can't publish to a channel group. You can only subscribe to it. To publish within the channel group, you need to publish to each channel individually.
:::

## Add channels to a channel group

:::note Requires Stream Controller add-on
This method requires that the *Stream Controller* add-on is enabled for your key in the PubNub [Admin Portal](https://admin.pubnub.com/). Read the [support page](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-) on enabling add-on features on your keys.
:::

This function adds channels to a channel group.

### Method(s)

`Adding Channels` is accomplished by using the following method(s) in the Windows C++ SDK:

:::note Maximum number of channels
You can add up to 200 channels to a channel group per API call.
:::

```cpp
add_channel_to_group(std::vector<std::string> const &channel, std::vector<std::string> const &channel_group)
```

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| channel | std::vector | Yes |  | The `channel(s)` vector to add to the channel group. |
| channel_group | std::vector<std::string>const | Yes |  | The `channel_group` to add to the `channel(s)`. |

A future result `(pubnub::futres)`. If transaction is successful, the response will be available via `get_channel()` function as one channel, a JSON object.

```cpp
add_channel_to_group (std::string const &channel, std::string const &channel_group)
```

| Parameter | Description |
| --- | --- |
| `channel` *Type: std::string const & | The `channel(s)` to add to the `channel group`. |
| `channel_group` *Type: std::string const & | The `channel_group` to add the `channel(s)` to. |

A future result `(pubnub::futres)`. If transaction is successful, the response will be available via `get_channel()` function as one channel, a JSON object.

### Sample code

#### Add channels

```cpp
const std::string channel_group("family");
```

```cpp
//Sync
static void add_channel(pubnub::context &pn) {
  enum pubnub_res res;

  try {
    res = pn.add_channel_to_group("wife", channel_group).await();

    if (PNR_OK == res) {
      std::cout <<  pn.get_channel() << std::endl;
    } else {
      std::cout << "Failed with code " << res << std::endl;
    }
  } catch (std::exception &ex) {
    std::cout << "Exception: " << ex.what() << std::endl;
  }
}

//Lambdas
static void add_channel(pubnub::context &ipn) {
  ipn.add_channel_to_group("wife", channel_group)
    .then([=](https://www.pubnub.com/docs/pubnub::context &pn, pubnub_res res) {
      if (PNR_OK == res) {
        std::cout <<  pn.get_channel() << std::endl;
      } else {
        std::cout << "Failed with code " << res << std::endl;
      }
  });
}

//Functions
static void on_added(pubnub::context &pn, pubnub_res res) {
  if (PNR_OK == res) {
    std::cout <<  pn.get_channel() << std::endl;
  } else {
    std::cout << "Failed with code " << res << std::endl;
  }
}

static void add_channel(pubnub::context &ipn) {
  ipn.add_channel_to_group("wife", channel_group).then(on_added);
}
```

### Rest response from server

```json
{
    "service" : "channel-registry",
    "status"  : 200,
    "error"   : false,
    "message" : "OK"
}
```

## List channels in a channel group

:::note Requires Stream Controller add-on
This method requires that the *Stream Controller* add-on is enabled for your key in the [Admin Portal](https://admin.pubnub.com/). Read the [support page](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-) on enabling add-on features on your keys.
:::

This function lists all channels in a channel group.

### Method(s)

`Listing Channels` is accomplished by using the following method(s) in the Windows C++ SDK:

```cpp
list_channel_group (std::string const &channel_group)
```

| Parameter | Description |
| --- | --- |
| `channel_group` *Type: std::string const & | `channel_group` to fetch the channels of. |

### Sample code

#### List channels

```cpp
const std::string channel_group("family");
```

```cpp
//Sync
static void list_channels(pubnub::context &pn) {
  enum pubnub_res res;

  try {
    res = pn.list_channel_group(channel_group).await();

    if (PNR_OK == res) {
      std::cout <<  pn.get_channel() << std::endl;
    } else {
      std::cout << "Failed with code " << res << std::endl;
    }
  } catch (std::exception &ex) {
    std::cout << "Exception: " << ex.what() << std::endl;
  }
}

//Lambdas
static void list_channels(pubnub::context &ipn) {
  ipn.list_channel_group(channel_group)
    .then([=](https://www.pubnub.com/docs/pubnub::context &pn, pubnub_res res) {
      if (PNR_OK == res) {
        std::cout <<  pn.get_channel() << std::endl;
      } else {
        std::cout << "Failed with code " << res << std::endl;
      }
  });
}

//Functions
static void on_list_received(pubnub::context &pn, pubnub_res res) {
  if (PNR_OK == res) {
    std::cout <<  pn.get_channel() << std::endl;
  } else {
    std::cout << "Failed with code " << res << std::endl;
  }
}

static void list_channels(pubnub::context &ipn) {
  ipn.list_channel_group(channel_group).then(on_list_received);
}
```

### Rest response from server

```json
{
    "status" : 200,
    "payload" : {
        "channels" : ["hi"],
        "group" : "abcd"
    },
    "service" : "channel-registry",
    "error" : False
}
```

## Remove channels from a channel group

:::note Requires Stream Controller add-on
This method requires that the *Stream Controller* add-on is enabled for your key in the [Admin Portal](https://admin.pubnub.com/). Read the [support page](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-) on enabling add-on features on your keys.
:::

This function removes channels from the channel group.

### Method(s)

`Removing Channels` is accomplished by using the following method(s) in the Windows C++ SDK:

```cpp
remove_channel_from_group (std::string const &channel, std::string const &channel_group)
```

| Parameter | Description |
| --- | --- |
| `channel_group` *Type: std::string const & | Specifies `channel_group` to remove the channels from. |
| `channel` *Type: std::string const & | The `channel` to remove from the `channel group`. |

### Sample code

Removing channels :

```cpp
const std::string channel_group("family");
```

```cpp
//Sync
static void remove_channel(pubnub::context &pn) {
  enum pubnub_res res;

  try {
    res = pn.remove_channel_from_group("son", channel_group).await();

    if (PNR_OK == res) {
      std::cout <<  pn.get_channel() << std::endl;
    } else {
      std::cout << "Failed with code " << res << std::endl;
    }
  } catch (std::exception &ex) {
    std::cout << "Exception: " << ex.what() << std::endl;
  }
}

//Lambdas

static void remove_channel(pubnub::context &ipn) {
  ipn.remove_channel_from_group("son", channel_group)
    .then([=](https://www.pubnub.com/docs/pubnub::context &pn, pubnub_res res) {
      if (PNR_OK == res) {
        std::cout <<  pn.get_channel() << std::endl;
      } else {
        std::cout << "Failed with code " << res << std::endl;
      }
  });
}

//Functions
static void on_removed(pubnub::context &pn, pubnub_res res) {
  if (PNR_OK == res) {
    std::cout <<  pn.get_channel() << std::endl;
  } else {
    std::cout << "Failed with code " << res << std::endl;
  }
}

static void remove_channel(pubnub::context &ipn) {
  ipn.remove_channel_from_group("son", channel_group).then(on_removed);
}
```

### Rest response from server

```json
{
    "status" : 200,
    "message" : "OK",
    "service" : "channel-registry",
    "error" : False
}
```

## Delete a channel group

:::note Requires Stream Controller add-on
This method requires that the *Stream Controller* add-on is enabled for your key in the [Admin Portal](https://admin.pubnub.com/). Read the [support page](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-) on enabling add-on features on your keys.
:::

This function removes the channel group.

### Method(s)

`Deleting Channel Group` is accomplished by using the following method(s) in the Windows C++ SDK:

```cpp
remove_channel_group (std::string const &channel_group)
```

| Parameter | Description |
| --- | --- |
| `channel_group` *Type: std::string const & | Specifies `channel_group` to remove. |

### Sample code

Deleting Channel Group :

```cpp
const std::string channel_group("family");
```

```cpp
//Sync
static void remove_group(pubnub::context &pn) {
  enum pubnub_res res;

  try {
    res = pn.remove_channel_group(channel_group).await();

    if (PNR_OK == res) {
      std::cout <<  pn.get_channel() << std::endl;
    } else {
      std::cout << "Failed with code " << res << std::endl;
    }
  } catch (std::exception &ex) {
    std::cout << "Exception: " << ex.what() << std::endl;
  }
}

//Lambdas
static void remove_group(pubnub::context &ipn) {
  ipn.remove_channel_group(channel_group)
    .then([=](https://www.pubnub.com/docs/pubnub::context &pn, pubnub_res res) {
      if (PNR_OK == res) {
        std::cout <<  pn.get_channel() << std::endl;
      } else {
        std::cout << "Failed with code " << res << std::endl;
      }
  });
}

//Functions
static void on_group_removed(pubnub::context &pn, pubnub_res res) {
  if (PNR_OK == res) {
    std::cout <<  pn.get_channel() << std::endl;
  } else {
    std::cout << "Failed with code " << res << std::endl;
  }
}

static void remove_group(pubnub::context &ipn) {
  ipn.remove_channel_group(channel_group).then(on_group_removed);
}
```

### Rest response from server

```json
{
    "status" : 200,
    "message" : "OK",
    "service" : "channel-registry",
    "error" : False
}
```

## Terms in this document

* **Channel** - A pathway for sending and receiving messages between devices, created automatically when you first use it, that can handle any number of users and messages for different communication needs, like 1-1 text chats, group conversations, and other data streaming.
* **PubNub** - PubNub is a real-time messaging platform that provides APIs and SDKs for building scalable applications. It handles the complex infrastructure of real-time communication, including: Message delivery and persistence, Presence detection, Access control, Push notifications, File sharing, Serverless processing with Functions and Events & Actions, Analytics and monitoring with BizOps Workspace, AI-powered insights with Illuminate.