zoukankan      html  css  js  c++  java
  • C++:在程序中获取全球唯一标识号(GUID或UUID)

    Windows:使用CoCreateGuid函数(GUID)

    1. #include <objbase.h>  
    2. #include <stdio.h>  
    3.   
    4. #define GUID_LEN 64  
    5.   
    6. int main(int argc, char* argv[])  
    7. {  
    8.     char buffer[GUID_LEN] = { 0 };  
    9.     GUID guid;  
    10.   
    11.     if ( CoCreateGuid(&guid) )  
    12.     {  
    13.         fprintf(stderr, "create guid error ");  
    14.         return -1;  
    15.     }  
    16.     _snprintf(buffer, sizeof(buffer),   
    17.         "%08X-%04X-%04x-%02X%02X-%02X%02X%02X%02X%02X%02X",   
    18.         guid.Data1, guid.Data2, guid.Data3,   
    19.         guid.Data4[0], guid.Data4[1], guid.Data4[2],   
    20.         guid.Data4[3], guid.Data4[4], guid.Data4[5],   
    21.         guid.Data4[6], guid.Data4[7]);  
    22.     printf("guid: %s ", buffer);  
    23.   
    24.     return 0;  
    25. }  

    Linux:使用uuid_generate函数(UUID)

      1. //编译命令:gcc atemp.c -o atemp -luuid  
      2. #include <stdio.h>  
      3. #include <uuid/uuid.h>  
      4.   
      5. int main()   
      6. {   
      7.     uuid_t uu;  
      8.     int i;  
      9.     uuid_generate( uu );   
      10.   
      11.     for(i=0;i<16;i++)   
      12.     {   
      13.         printf("%02X-",uu[i]);   
      14.     }   
      15.     printf(" ");   
      16.   
      17.     return 0;   
      18. }   
  • 相关阅读:
    无标题
    UVA 11987 并查集删点
    屯题 (bestcoder #62~#75)
    codeforces 293E Close Vertices 点分治+滑窗+treap
    hdu4670 Cube number on a tree 点分治
    hdu4812 D Tree 点分治
    poj2112 Boatherds 点分治
    HDU 4866 Shooting 二分+主席树
    poj1741 Tree 点分治
    关于点分治。。。
  • 原文地址:https://www.cnblogs.com/lidabo/p/3602038.html
Copyright © 2011-2022 走看看