首页 > 编程语言 > 详细

C++ write time string and uuid to file

时间:2021-05-24 22:34:01      阅读:15      评论:0      收藏:0      [点我收藏+]
#pragma comment(lib, "rpcrt4.lib")
#include <iostream>
#include <time.h>
#include <windows.h>
#include <sstream>
#include <fstream>
 
using namespace std;

string getTimeStringDemo1();
string getUuidDemo2();
void writeFileDemo3();

int main()
{
    writeFileDemo3();
    getchar();
}

void writeFileDemo3()
{ 
    ofstream writeFile("timeUUid.txt", std::ios::app);
    if (!writeFile)
    {
        cout << "Create or open timeUUid.txt failed! " << endl;
    }
    stringstream ss;
    unsigned long long num = 0;
    for (int i = 0; i < INT16_MAX; i++)
    { 
        for (int i = 0; i < 100000; i++)
        {
            ss << getTimeStringDemo1() << "," << getUuidDemo2() << endl;
            num++;
        }
        writeFile << ss.str() << endl;
        cout << "Now is " << getTimeStringDemo1() << ",num =" << num << endl;
    } 
}

string getUuidDemo2()
{
    UUID uuid;
    UuidCreate(&uuid);
    char* str;
    UuidToStringA(&uuid, (RPC_CSTR*)&str);
    return str;
}

string getTimeStringDemo1()
{
    time_t rawTime = time(NULL);
    struct tm info;
    localtime_s(&info, &rawTime);
    char str[100];
    strftime(str, 100, "%Y%m%d%H%M%S", &info);
    return str;
}

技术分享图片

 

C++ write time string and uuid to file

原文:https://www.cnblogs.com/Fred1987/p/14805906.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!