String for boost :: uuid conversion

I was just starting to use boost in C ++, and I just wanted to ask a couple of questions regarding uuids.

I am uploading a file that requires me to know uuids, so I can link some objects together. For this reason, I am trying to write my own uuids, but I'm not sure if there are any special conditions for strings, etc., since the strings I used (usually something basic) do not work. Can someone point me in the right direction? I tried using a line generator, but don't mean anything yet, so I assume that something is wrong with my lines (which were currently just random words).

Here is an example of a short example, cannot give real code:

void loadFiles(std::string xmlFile);

void linkObjects(custObj network)
{
    for (int i = 0; i < network->getLength(); i++)
    {
        network[i]->setId([boost::uuid]);  
        if (i > 0)
            network[i]->addObj(network[i-1]->getId());
    }
}
+4
1

" ". ,

uuids Boost Uuid.

#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <boost/uuid/random_generator.hpp>
#include <boost/lexical_cast.hpp>

using namespace boost::uuids;

int main()
{
    random_generator gen;

    for (int i = 0; i < 10; ++i)
    {
        uuid new_one = gen(); // here how you generate one

        std::cout << "You can just print it: " << new_one << "; ";

        // or assign it to a string
        std::string as_text = boost::lexical_cast<std::string>(new_one);

        std::cout << "as_text: '" << as_text << "'\n";

        // now, read it back in:
        uuid roundtrip = boost::lexical_cast<uuid>(as_text);

        assert(roundtrip == new_one);
    }
}

Live On Coliru

+5

Source: https://habr.com/ru/post/1528875/


All Articles