C++ : Generating UUID

Boost is a collection of very powerful libraries for C++. We could use boost to generate UUIDs.
The header file <boost/uuid/uuid.hpp> provides an implementation of the Universally Unique Identifiers (UUID).

A definition of UUID could be found in RFC 4122

UUID applications

  • UUIDs can be used to identify persistent objects (physical machines, vms) across a network.
  • UUIDs can be used to tags machines, vms etc.
  • UUIDs can be used in databases to identify various records or rows.

Boost library used : 1_77_0

Program : C++ program for generating UUID using boost library.

#include <iostream>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <boost/lexical_cast.hpp>

namespace boost_uuid = boost::uuids;
int main() {

    const std :: string uuid_str = boost::lexical_cast<std::string>(boost::uuids::random_generator()());
    std::cout << uuid_str << std::endl;
    return 0;



Copyright (c) 2019-2021, Algotree.org.
All rights reserved.