Exercism c++ problem

Since the OP has already been handed a ready made solution, I feel it will not be doing any harm to add yet another one and, anyway, I guess his professor will being seeing a stack of similar AI generated solutions.
Here I used Deep Seek to produce a solution based on a recursive lambda function which should distinguish it from the other solutions that will be provided. It looks plausible enough but I've not tested it.

#include <iostream>
#include <functional>  // Required for std::function

int main() {
    unsigned int number;
    std::cout << "Enter a number: ";
    std::cin >> number;

    // Recursive lambda (requires std::function)
    std::function<int(unsigned int)> count_ones = [&](unsigned int num) {
        return (num == 0) ? 0 : 1 + count_ones(num & (num - 1));
    };

    std::cout << "Number of 1 bits: " << count_ones(number) << std::endl;
    return 0;
}