質問

C ++でブーストを使い始めたばかりで、UUIDに関するいくつかの質問をしたいだけでした。

私は私がUUIDを知っている必要があるファイルにロードしているので、いくつかのオブジェクトをまとめてリンクできます。このため、私は自分のUUIDを書いていますが、私が使用してきた文字列としての文字列の特別な条件があるかどうかわからない(通常は基本的なもの)が機能していません。誰かが正しい方向に私を指していることができますか?私は文字列ジェネレータを使ってみましたが、これまでのところ、無駄なことはありませんので、私の文字列(現在はランダムな言葉があっただけの)何か問題があると思います。

これは一種のものです、実際のコードを与えることはできません:

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());
    }
}
.

役に立ちましたか?

解決

私はあなたの質問を「サンプルが必要」としました。これが

を示すサンプルです

  • 読書
  • writing
  • 生成
  • を比較する

ブーストUUIDを持つ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's 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);
    }
}
.

それは見てください コリル

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top