Example of UUID generation using Boost in C++

后端 未结 2 1017
无人及你
无人及你 2020-12-04 08:43

I want to generate just random UUID\'s, as it is just important for instances in my program to have unique identifiers. I looked into Boost UUID, but I can\'t manage to gene

2条回答
  •  旧时难觅i
    2020-12-04 09:03

    The answer of Georg Fritzsche is ok but maybe a bit misleading. You should reuse the generator if you need more than one uuid. Maybe it's clearer this way:

    #include 
    
    #include             // uuid class
    #include  // generators
    #include          // streaming operators etc.
    
    
    int main()
    {
        boost::uuids::random_generator generator;
    
        boost::uuids::uuid uuid1 = generator();
        std::cout << uuid1 << std::endl;
    
        boost::uuids::uuid uuid2 = generator();
        std::cout << uuid2 << std::endl;
    
        return 0;
    }
    

提交回复
热议问题