首页 > 编程语言 >Visual C++ generate uuid via UuidCreate and CoCreateGuid,get time now,write string to file

Visual C++ generate uuid via UuidCreate and CoCreateGuid,get time now,write string to file

时间:2024-07-02 15:57:40浏览次数:1  
标签:std now via uuid tm file time include

// ConsoleApplication3.cpp : This file contains the 'main' function. Program execution begins and ends there.
// 
#pragma comment(lib, "rpcrt4.lib") 
#include <windows.h>
#include <chrono>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <rpcdce.h> 
#include <sstream>
#include <thread>
#include <uuids.h> 
 

using namespace std;

std::string get_time_now()
{
    auto now = std::chrono::system_clock::now();
    time_t raw_time = std::chrono::system_clock::to_time_t(now);
    struct tm tm_info;
    localtime_s(&tm_info, &raw_time);
    std::stringstream ss;
    ss << std::put_time(&tm_info, "%Y%m%d%H%M%S");
    return ss.str();
}

string get_UuidCreate()
{
    RPC_CSTR rpcStr;
    string uuidValue;
    UUID newUUID;
    UuidCreate(&newUUID);
    UuidToStringA(&newUUID, &rpcStr);
    uuidValue = (char*)rpcStr;
    RpcStringFreeA(&rpcStr);
    return uuidValue;
}

std::string get_CoCreateGuid()
{
    std::string result;
    GUID guid;

    if (S_OK == CoCreateGuid(&guid))
    {
        char* buffer = new char[36];
        snprintf(buffer, 36, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
            guid.Data1, guid.Data2, guid.Data3, guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]);
        result = std::string(buffer);
    } 
    return result;
}

void write_content_to_file(std::string file_name, std::string content_str)
{
    fstream w_file(file_name, std::ios::app);
    if (!w_file.is_open())
    {
        std::cout << "Create or open " << file_name << " failed!" << std::endl;
        return;
    }
    w_file << content_str << std::endl;
    w_file << std::endl;
    std::cout << get_time_now() << ",finished in " << __FUNCSIG__ << std::endl;
}

int main()
{
    std::cout << get_time_now() << ",started in " << __FUNCSIG__ << std::endl;
    std::stringstream ss;
    for (int i = 0; i < 1000000; i++)
    {
        ss << i + 1 << "," << get_UuidCreate() << "," << get_CoCreateGuid() << std::endl;
    }
    std::string file_name = get_time_now() + ".txt";
    write_content_to_file(file_name, ss.str());
    ss = std::stringstream();
    std::cout << ss.str() << std::endl;
    std::cout << get_time_now() << ",finished in " << __FUNCSIG__ << std::endl;
}


 

 

 

 

 

 

标签:std,now,via,uuid,tm,file,time,include
From: https://www.cnblogs.com/Fred1987/p/18280019

相关文章

  • [论文阅读] Calligraphy Font Generation via Explicitly Modeling Location-Aware Gl
    Pretitle:CalligraphyFontGenerationviaExplicitlyModelingLocation-AwareGlyphComponentDeformationssource:TMM2023paper:https://ieeexplore.ieee.org/document/10356848code:None关键词:generativeadversarialnetworks,imageprocessing,imagesynth......
  • rabbitmq 启动报错 unknown exchange type ‘x-delayed-message‘
    产生问题的原因rabbitmq中默认只有四中交换机类型:headers、direct、fanout、topic。所以我们需要自己安装一个x-delayed-message类型的交换机x-delayed-message的安装1、下载插件点击,下载rabbitmq_delayed_message_exchange-3.8.0.ez。2、将下载的包放到/RABBIT_HOME/plugin......
  • [HBM] HBM TSV (Through Silicon Via) 结构与工艺
    依公知及经验整理,原创保护,禁止转载。专栏《深入理解DDR》全文3300字。1概念1.1什么是HBMTSV使用TSV堆叠多个DDRDRAM成为一块HBM,成倍提高了存储器位宽,一条位宽相当于高速公路的一条车道,车道越多,在相同的车速下,传输运输量自然越大。1.2TSV优点(1)高密......
  • MODEL COMPRESSION VIA DISTILLATION AND QUANTIZATION翻译
    摘要:深度神经网络(DNNs)继续取得重大进展,解决了从图像分类到翻译或增强学习的任务。这个领域的一个受到广泛关注的方面是在资源受限环境中(如移动或嵌入式设备)高效执行深度模型。本文聚焦于这一问题,并提出了两种新的压缩方法,这两种方法共同利用了权重量化和大型网络(称为“教师”网络)......
  • GSVA: Generalized Segmentation via Multimodal Large Language Models论文阅读笔记
    Motivation&AbsGeneralizedReferringExpressionSegmentation(GRES):相比于原始的RES任务,一个文本描述里可能出现多个需要分割的物体,或者没有需要分割的物体,难点在于建模不同实体之间复杂的空间关系,以及识别不存在的描述。现有的方法如LISA难以处理GRES任务,为此作者提出了GSV......
  • WebService异常: 提供的 URI 方案“https”无效,应为“http”。 参数名: via
    解决如下:把节点 httpsTransport改为 httpTransport原配置:<bindings><customBinding><bindingname="ZWS_CUST"><mtomMessageEncodingmessageVersion="Soap11WSAddressing10"/>......
  • VC++ gen uuid and time
    //ConsoleApplication2.cpp:Thisfilecontainsthe'main'function.Programexecutionbeginsandendsthere.//#define_CRT_SECURE_NO_WARNINGS#pragmacomment(lib,"rpcrt4.lib")#include<windows.h>#include<rpcdce.h>#......
  • 知识库的创建(1) - KnowledgeFile文件加载和分割
    文章目录前言一、类的初始化方法`__init__`1.参数解析2.初始化步骤二、方法`file2docs`1.功能2.参数3.步骤三、方法`docs2texts`1.功能2.参数3.步骤四、方法`file2text`1.功能2.参数3.步骤五、方法`file_exist`1.功能2.返回3.方法`get_mtim......
  • 功能强大的多功能文档转换工具Neevia Document Converter Pro 7.5.0.241
    NeeviaDocumentConverterPro是一款功能强大的Windows软件,旨在将文档转换为各种格式,包括PDF、TIFF、JPEG和许多其他格式。该程序专为在企业环境中使用而设计,提供文档转换和处理过程的自动化,这使其成为处理大量文档的组织的***工具。NeeviaDocumentConverterPro的主要功......
  • 论文阅读:《Chinese Relation Extraction with Multi-Grained Information and Externa
    LiZ,DingN,LiuZ,etal.Chineserelationextractionwithmulti-grainedinformationandexternallinguisticknowledge[C]//Proceedingsofthe57thAnnualMeetingoftheAssociationforComputationalLinguistics.2019:4377-4386.该方法的github实现引言针......